%%
%% This is file `l3int.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3int.dtx  (with options: `package,trace')
%% 
%% 
%% EXPERIMENTAL CODE
%% 
%% Do not distribute this file without also distributing the
%% source files specified above.
%% 
%% Do not distribute a modified version of this file.
%% 
%% 
%% File: l3int.dtx Copyright (C) 1990-2008 LaTeX3 project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version.  The latest version
%% of this license is in the file
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% This file is part of the ``expl3 bundle'' (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%%    http://www.latex-project.org/cgi-bin/cvsweb.cgi/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %%
%%%%%%%%%%%
%%
%%   Snapshots taken from the repository represent work in progress and may
%%   not work or may contain conflicting material!  We therefore ask
%%   people _not_ to put them into distributions, archives, etc. without
%%   prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
\RequirePackage{l3names}
\GetIdInfo$Id: l3int.dtx 738 2008-08-01 13:21:42Z morten $
          {L3 Experimental Integer module}

\ProvidesExplPackage
  {\filename}{\filedate}{\fileversion}{\filedescription}
\RequirePackage{l3num}
\let_new:NN \int_to_roman:w \tex_romannumeral:D
\let_new:NN \int_to_number:w \tex_number:D
\let_new:NN \int_advance:w \tex_advance:D
\def_new:Npn \int_incr:N #1{\int_advance:w#1\c_one
}
\def_new:Npn \int_decr:N #1{\int_advance:w#1\c_minus_one
}
\def_new:Npn \int_gincr:N {
 \pref_global:D
   \int_incr:N}
\def_new:Npn \int_gdecr:N {
 \pref_global:D
   \int_decr:N}
\def:Npn \int_incr:N #1{\int_add:Nn#1\c_one}
\def:Npn \int_decr:N #1{\int_add:Nn#1\c_minus_one}
\def:Npn \int_gincr:N #1{\int_gadd:Nn#1\c_one}
\def:Npn \int_gdecr:N #1{\int_gadd:Nn#1\c_minus_one}
\def:Npn \int_incr:c {\exp_args:Nc\int_incr:N}
\def:Npn \int_decr:c {\exp_args:Nc\int_decr:N}
\def:Npn \int_gincr:c {\exp_args:Nc\int_gincr:N}
\def:Npn \int_gdecr:c {\exp_args:Nc\int_gdecr:N}
\let:NN \int_new:N \newcount% allocation better nick the LaTeX one...
\def_new:Npn \int_new:c {\exp_args:Nc \int_new:N}
\def_new:Npn \int_set:Nn #1#2{#1 \int_eval:w #2\int_eval_end:
}
\def_new:Npn \int_gset:Nn {
 \pref_global:D
   \int_set:Nn }
\def_new:Npn \int_set:cn {\exp_args:Nc \int_set:Nn }
\def_new:Npn \int_gset:cn {\exp_args:Nc \int_gset:Nn }
\def_new:Npn \int_zero:N  #1 {#1=\c_zero}
\def_new:Npn \int_zero:c  #1 {\exp_args:Nc \int_zero:N}
\def_new:Npn \int_gzero:N #1 {\pref_global:D #1=\c_zero}
\def_new:Npn \int_gzero:c {\exp_args:Nc \int_gzero:N}
\def_new:Npn \int_add:Nn #1#2{
    \int_advance:w #1 by \int_eval:w #2\int_eval_end:
}
\def_new:Npn\int_add:cn{\exp_args:Nc\int_add:Nn}
\def_new:Npn \int_sub:Nn #1#2{
    \int_advance:w #1-\int_eval:w #2\int_eval_end:
}
\def_new:Npn \int_gadd:Nn {
 \pref_global:D
   \int_add:Nn }
\def_new:Npn \int_gsub:Nn {
 \pref_global:D
   \int_sub:Nn }
\def_new:Npn \int_gadd:cn{\exp_args:Nc\int_gadd:Nn}
\def_new:Npn \int_sub:cn{\exp_args:Nc\int_sub:Nn}
\def_new:Npn \int_gsub:cn{\exp_args:Nc\int_gsub:Nn}
\let_new:NN \int_use:N \tex_the:D
\def_new:Npn \int_use:c #1{\int_use:N \cs:w#1\cs_end:}
\def_new:Npn \int_to_arabic:n #1{\int_to_number:w \int_eval:n{#1}}
\def_new:Npn \int_roman_lcuc_mapping:Nnn #1#2#3{
  \def:cpn {int_to_lc_roman_#1:}{#2}
  \def:cpn {int_to_uc_roman_#1:}{#3}
}
\int_roman_lcuc_mapping:Nnn i i I
\int_roman_lcuc_mapping:Nnn v v V
\int_roman_lcuc_mapping:Nnn x x X
\int_roman_lcuc_mapping:Nnn l l L
\int_roman_lcuc_mapping:Nnn c c C
\int_roman_lcuc_mapping:Nnn d d D
\int_roman_lcuc_mapping:Nnn m m M
\int_roman_lcuc_mapping:Nnn Q \use_none:nn \use_none:nn
\def_new:Npn \int_to_roman:n #1 {
  \exp_after:NN \int_to_roman_lcuc:NN \exp_after:NN l
    \int_to_roman:w \int_eval:n {#1} Q
}
\def_new:Npn \int_to_Roman:n #1 {
  \exp_after:NN \int_to_roman_lcuc:NN \exp_after:NN u
    \int_to_roman:w \int_eval:n {#1} Q
}
\def_new:Npn \int_to_roman_lcuc:NN #1#2{
  \cs_use:c {int_to_#1c_roman_#2:}
  \int_to_roman_lcuc:NN #1
}
\def:Npn \int_convert_number_with_rule:nnN #1#2#3{
  \int_compare:nNnTF {#1}>{#2}
  {
    \exp_args:No \int_convert_number_with_rule:nnN
      { \int_use:N\int_div_truncate:nn {#1-1}{#2} }{#2}
      #3
    \exp_args:No #3 { \int_use:N\int_eval:n{1+\int_mod:nn {#1-1}{#2}} }
  }
  { \exp_args:No #3{ \int_use:N\int_eval:n{#1} } }
}
\def_new:Npn \int_alph_default_conversion_rule:n #1{
  \if_case:w #1
    \or: a\or: b\or: c\or: d\or: e\or: f
    \or: g\or: h\or: i\or: j\or: k\or: l
    \or: m\or: n\or: o\or: p\or: q\or: r
    \or: s\or: t\or: u\or: v\or: w\or: x
    \or: y\or: z
  \fi:
}
\def_new:Npn \int_Alph_default_conversion_rule:n #1{
  \if_case:w #1
    \or: A\or: B\or: C\or: D\or: E\or: F
    \or: G\or: H\or: I\or: J\or: K\or: L
    \or: M\or: N\or: O\or: P\or: Q\or: R
    \or: S\or: T\or: U\or: V\or: W\or: X
    \or: Y\or: Z
  \fi:
}
\def_new:Npn \int_to_alph:n #1{
  \int_convert_number_with_rule:nnN {#1}{26}
    \int_alph_default_conversion_rule:n
}
\def_new:Npn \int_to_Alph:n #1{
  \int_convert_number_with_rule:nnN {#1}{26}
    \int_Alph_default_conversion_rule:n
}
\def_new:Npn \int_to_symbol:n #1{
  \mode_if_math:TF
  {
    \int_convert_number_with_rule:nnN {#1}{9}
      \int_symbol_math_conversion_rule:n
  }
  {
    \int_convert_number_with_rule:nnN {#1}{9}
      \int_symbol_text_conversion_rule:n
  }
}
\def_new:Npn \int_symbol_math_conversion_rule:n #1 {
  \if_case:w #1
    \or: *
    \or: \dagger
    \or: \ddagger
    \or: \mathsection
    \or: \mathparagraph
    \or: \|
    \or: **
    \or: \dagger\dagger
    \or: \ddagger\ddagger
  \fi:
}
\def_new:Npn \int_symbol_text_conversion_rule:n #1 {
  \if_case:w #1
    \or: \textasteriskcentered
    \or: \textdagger
    \or: \textdaggerdbl
    \or: \textsection
    \or: \textparagraph
    \or: \textbardbl
    \or: \textasteriskcentered\textasteriskcentered
    \or: \textdagger\textdagger
    \or: \textdaggerdbl\textdaggerdbl
  \fi:
}
\int_new:N \l_tmpa_int
\int_new:N \l_tmpb_int
\int_new:N \l_tmpc_int
\int_new:N \g_tmpa_int
\int_new:N \g_tmpb_int
\int_new:N \l_loop_int  % a variable for use in loops (whilenum etc)
\let_new:NN \int_eval:n    \num_eval:n
\let_new:NN \int_eval:w    \num_eval:w
\let_new:NN \int_eval_end: \num_eval_end:
\const_new:Nn \c_max_int {2147483647}
\def:Npn \int_pre_eval_one_arg:Nnn #1#2{\exp_args:No#1{\int_eval:w#2}}
\def:Npn \int_pre_eval_two_args:Nnn #1#2#3{
  \exp_args:Noo#1{\int_use:N\int_eval:w#2}{\int_use:N\int_eval:w#3}
}
\def_new:Npn \int_div_truncate:nn {
  \int_pre_eval_two_args:Nnn\int_div_truncate_raw:nn
}
\def_new:Npn \int_div_truncate_raw:nn #1#2 {
  \int_eval:w
    \if_num:w \int_eval:w#1 = \c_zero
      0
    \else:
      (#1
      \if_num:w  \int_eval:w #1 < \c_zero
        \if_num:w \int_eval:w#2 < \c_zero
          -( #2 +
        \else:
          +( #2 -
        \fi:
      \else:
        \if_num:w \int_eval:w #2 < \c_zero
          +( #2 +
        \else:
          -( #2 -
        \fi:
      \fi:
      1)/2)
    \fi:
    /(#2)
  \int_eval_end:
}
\def_new:Npn \int_div_round:nn {
  \int_pre_eval_two_args:Nnn\int_div_round_raw:nn
}
\def_new:Npn \int_div_round_raw:nn #1#2 {\int_eval:n{#1/#2}}
\def_new:Npn \int_mod:nn {\int_pre_eval_two_args:Nnn\int_mod_raw:nn}
\def_new:Npn \int_mod_raw:nn #1#2 {
  \int_eval:n{ #1 - \int_div_truncate_raw:nn {#1}{#2} * #2 }
}
\let_new:NN \int_compare:nNnTF \num_compare:nNnTF
\let_new:NN \int_compare:nNnT \num_compare:nNnT
\let_new:NN \int_compare:nNnF \num_compare:nNnF
\let_new:NN \int_max_of:nn \num_max_of:nn
\let_new:NN \int_min_of:nn \num_min_of:nn
\let_new:NN \int_abs:nn \num_abs:nn
\let_new:NN \int_compare_p:nNn \num_compare_p:nNn
\def_new:Npn \int_if_odd_p:n #1 {
  \if_num_odd:w \int_eval:n{#1}
    \c_true
  \else:
    \c_false
  \fi:
}
\def_test_function_new:npn {int_if_odd:n}#1{\if_num_odd:w \int_eval:n{#1}}
\def_long_new:Npn \int_whiledo:nNnT #1#2#3#4{
  \int_compare:nNnT {#1}#2{#3}{#4 \int_whiledo:nNnT {#1}#2{#3}{#4}}
}
\def_long_new:Npn \int_whiledo:nNnF #1#2#3#4{
  \int_compare:nNnF {#1}#2{#3}{#4 \int_whiledo:nNnF {#1}#2{#3}{#4}}
}
\def_long_new:Npn \int_dowhile:nNnT #1#2#3#4{
  #4 \int_compare:nNnT {#1}#2{#3}{\int_dowhile:nNnT {#1}#2{#3}{#4}}
}
\def_long_new:Npn \int_dowhile:nNnF #1#2#3#4{
  #4 \int_compare:nNnF {#1}#2{#3}{\int_dowhile:nNnF {#1}#2{#3}{#4}}
}
\def_new:Npn \int_get_sign_and_digits:n #1{
  \int_get_sign_and_digits_aux:nNNN {#1} \c_true \c_true \c_true
}
\def_new:Npn \int_get_sign:n #1{
  \int_get_sign_and_digits_aux:nNNN {#1} \c_true \c_true \c_false
}
\def_new:Npn \int_get_digits:n #1{
  \int_get_sign_and_digits_aux:nNNN {#1} \c_true \c_false \c_true
}
\def_new:Npn \int_get_sign_and_digits_aux:nNNN #1#2#3#4{
  \tlist_if_head_eq_charcode:fNTF {#1} -
  {
    \bool_if:NTF #2
    { \int_get_sign_and_digits_aux:oNNN {\use_none:n #1} \c_false #3#4 }
    { \int_get_sign_and_digits_aux:oNNN {\use_none:n #1} \c_true  #3#4 }
  }
  {
    \tlist_if_head_eq_charcode:fNTF {#1} +
    { \int_get_sign_and_digits_aux:oNNN {\use_none:n #1} #2#3#4}
    {
      \bool_double_if:NNnnnn #3#4
      { \bool_if:NF #2 - #1 }
      { \bool_if:NF #2 -    }
      { #1 }  {  }
    }
  }
}
\def_new:Npn \int_get_sign_and_digits_aux:oNNN{
  \exp_args:No\int_get_sign_and_digits_aux:nNNN
}
\def:Npn \int_convert_from_base_ten:nn#1#2{
  \num_compare:nNnTF {#1}<\c_zero
  {
    - \int_convert_from_base_ten_aux:non {}
    { \int_use:N \int_eval:n {-#1} }
  }
  {
    \int_convert_from_base_ten_aux:non {}
    { \int_use:N \int_eval:n {#1} }
  }
  {#2}
}
\def_new:Npn \int_convert_from_base_ten_aux:nnn#1#2#3{
  \num_compare:nNnTF {#2}<{#3}
  { \int_convert_number_to_letter:n{#2} #1 }
  {
    \int_convert_from_base_ten_aux:fon
    {
      \int_convert_number_to_letter:n {\int_use:N\int_mod_raw:nn {#2}{#3}}
      #1
    }
    {\int_use:N \int_div_truncate_raw:nn{#2}{#3}}
    {#3}
  }
}
\def:Npn \int_convert_from_base_ten_aux:non{
  \exp_args:Nno\int_convert_from_base_ten_aux:nnn
}
\def:Npn \int_convert_from_base_ten_aux:fon{
  \exp_args:Nfo\int_convert_from_base_ten_aux:nnn
}
\def:Npn \int_convert_number_to_letter:n #1{ \if_case:w \int_eval:w
  #1-10\scan_stop: \exp_after:NN A \or: \exp_after:NN B \or:
  \exp_after:NN C \or: \exp_after:NN D \or: \exp_after:NN E \or:
  \exp_after:NN F \or: \exp_after:NN G \or: \exp_after:NN H \or:
  \exp_after:NN I \or: \exp_after:NN J \or: \exp_after:NN K \or:
  \exp_after:NN L \or: \exp_after:NN M \or: \exp_after:NN N \or:
  \exp_after:NN O \or: \exp_after:NN P \or: \exp_after:NN Q \or:
  \exp_after:NN R \or: \exp_after:NN S \or: \exp_after:NN T \or:
  \exp_after:NN U \or: \exp_after:NN V \or: \exp_after:NN W \or:
  \exp_after:NN X \or: \exp_after:NN Y \or: \exp_after:NN Z \else:
  \use_arg_i_after_fi:nw{ #1 }\fi: }
\def:Npn \int_convert_to_base_ten:nn #1#2 {
  \int_use:N\int_eval:n{
    \int_get_sign:n{#1}
    \exp_args:Nf\int_convert_to_base_ten_aux:nn {\int_get_digits:n{#1}}{#2}
  }
}
\def_new:Npn \int_convert_to_base_ten_aux:nn #1#2{
  \int_convert_to_base_ten_auxi:nnN {0}{#2} #1 \q_nil
}
\def_new:Npn \int_convert_to_base_ten_auxi:nnN#1#2#3{
  \quark_if_nil:NTF #3
  {#1}
  {\exp_args:No\int_convert_to_base_ten_auxi:nnN
    {\int_use:N \int_eval:n{ #1*#2+\int_convert_letter_to_number:N #3} }
    {#2}
  }
}
\def:Npn \int_convert_letter_to_number:N #1{
  \int_compare:nNnTF{`#1}<{58}{#1}
  {
    \int_eval:n{ `#1 -
      \if:w\int_compare_p:nNn{`#1}<{91}
      55
      \else:
      87
      \fi:
    }
  }
}
%% 
%%
%% End of file `l3int.sty'.
