%% %% This is file `l3int.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% l3int.dtx (with options: `package') %% %% 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-2011 The 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/svnroot/experimental/trunk/ %% %% 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 LaTeX3 Project. %% %% ----------------------------------------------------------------------- \RequirePackage{l3names} \GetIdInfo$Id: l3int.dtx 2666 2011-08-26 06:10:09Z joseph $ {L3 Experimental integers} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} \package_check_loaded_expl: \cs_new_eq:NN \int_value:w \tex_number:D \cs_new_eq:NN \int_eval:w \etex_numexpr:D \cs_new_eq:NN \int_eval_end: \tex_relax:D \cs_new_eq:NN \if_num:w \tex_ifnum:D \cs_new_eq:NN \if_int_odd:w \tex_ifodd:D \cs_new_eq:NN \if_case:w \tex_ifcase:D \cs_new:Npn \int_eval:n #1 { \int_value:w \int_eval:w #1 \int_eval_end: } \cs_new:Npn \int_abs:n #1 { \int_value:w \if_int_compare:w \int_eval:w #1 < \c_zero - \fi: \int_eval:w #1 \int_eval_end: } \cs_new:Npn \int_max:nn #1#2 { \int_value:w \int_eval:w \if_int_compare:w \int_eval:w #1 > \int_eval:w #2 \int_eval_end: #1 \else: #2 \fi: \int_eval_end: } \cs_new:Npn \int_min:nn #1#2 { \int_value:w \int_eval:w \if_int_compare:w \int_eval:w #1 < \int_eval:w #2 \int_eval_end: #1 \else: #2 \fi: \int_eval_end: } \cs_new:Npn \int_div_truncate:nn #1#2 { \int_value:w \int_eval:w \if_int_compare:w \int_eval:w #1 = \c_zero 0 \else: ( #1 % ) \if_int_compare:w \int_eval:w #1 < \c_zero \if_int_compare:w \int_eval:w #2 < \c_zero - ( #2 + % ) \else: + ( #2 - % ) \fi: \else: \if_int_compare:w \int_eval:w #2 < \c_zero + ( #2 + % ) \else: - ( #2 - % ) \fi: \fi: % ( ( 1 ) / 2 ) \fi: / ( #2 ) \int_eval_end: } \cs_new:Npn \int_div_round:nn #1#2 { \int_eval:n { ( #1 ) / ( #2 ) } } \cs_new:Npn \int_mod:nn #1#2 { \int_value:w \int_eval:w #1 - \int_div_truncate:nn {#1} {#2} * ( #2 ) \int_eval_end: } \cs_new_protected_nopar:Npn \int_new:N #1 { \chk_if_free_cs:N #1 \newcount #1 } \cs_generate_variant:Nn \int_new:N { c } \cs_new_protected_nopar:Npn \int_const:Nn #1#2 { \int_compare:nNnTF {#2} > \c_minus_one { \int_compare:nNnTF {#2} > \c_max_register_int { \int_new:N #1 \int_gset:Nn #1 {#2} } { \chk_if_free_cs:N #1 \pref_global:D \tex_mathchardef:D #1 = \int_eval:w #2 \int_eval_end: } } { \int_new:N #1 \int_gset:Nn #1 {#2} } } \cs_generate_variant:Nn \int_const:Nn { c } \cs_new_protected_nopar:Npn \int_zero:N #1 { #1 = \c_zero } \cs_new_protected_nopar:Npn \int_gzero:N #1 { \pref_global:D #1 = \c_zero } \cs_generate_variant:Nn \int_zero:N { c } \cs_generate_variant:Nn \int_gzero:N { c } \cs_new_protected_nopar:Npn \int_set_eq:NN #1#2 { #1 = #2 } \cs_generate_variant:Nn \int_set_eq:NN { c } \cs_generate_variant:Nn \int_set_eq:NN { Nc , cc } \cs_new_protected_nopar:Npn \int_gset_eq:NN #1#2 { \pref_global:D #1 = #2 } \cs_generate_variant:Nn \int_gset_eq:NN { c } \cs_generate_variant:Nn \int_gset_eq:NN { Nc , cc } \cs_new_protected_nopar:Npn \int_add:Nn #1#2 { \tex_advance:D #1 by \int_eval:w #2 \int_eval_end: } \cs_new_nopar:Npn \int_sub:Nn #1#2 { \tex_advance:D #1 by - \int_eval:w #2 \int_eval_end: } \cs_new_protected_nopar:Npn \int_gadd:Nn { \pref_global:D \int_add:Nn } \cs_new_protected_nopar:Npn \int_gsub:Nn { \pref_global:D \int_sub:Nn } \cs_generate_variant:Nn \int_add:Nn { c } \cs_generate_variant:Nn \int_gadd:Nn { c } \cs_generate_variant:Nn \int_sub:Nn { c } \cs_generate_variant:Nn \int_gsub:Nn { c } \cs_new_protected_nopar:Npn \int_incr:N #1 { \tex_advance:D #1 \c_one } \cs_new_protected_nopar:Npn \int_decr:N #1 { \tex_advance:D #1 \c_minus_one } \cs_new_protected_nopar:Npn \int_gincr:N { \pref_global:D \int_incr:N } \cs_new_protected_nopar:Npn \int_gdecr:N { \pref_global:D \int_decr:N } \cs_generate_variant:Nn \int_incr:N { c } \cs_generate_variant:Nn \int_decr:N { c } \cs_generate_variant:Nn \int_gincr:N { c } \cs_generate_variant:Nn \int_gdecr:N { c } \cs_new_protected_nopar:Npn \int_set:Nn #1#2 { #1 ~ \int_eval:w #2\int_eval_end: } \cs_new_protected_nopar:Npn \int_gset:Nn { \pref_global:D \int_set:Nn } \cs_generate_variant:Nn \int_set:Nn { c } \cs_generate_variant:Nn \int_gset:Nn { c } \cs_new_eq:NN \int_use:N \tex_the:D \cs_new_nopar:Npn \int_use:c #1 { \int_use:N \cs:w #1 \cs_end: } \prg_new_conditional:Npnn \int_compare:n #1 { p , T , F , TF } { \exp_after:wN \int_compare_aux:nw \int_value:w \int_eval:w #1 \q_stop } \cs_new:Npn \int_compare_aux:nw #1#2 \q_stop { \exp_after:wN \int_compare_aux:Nw \int_to_roman:w \if:w #1 - \else: - \fi: #1#2 \q_mark #1#2 \q_stop } \cs_new:Npn \int_compare_aux:Nw #1#2#3 \q_mark { \use:c { int_compare_ #1 \if_meaning:w = #2 = \fi: :w } } \cs_new:cpn { int_compare_=:w } #1 = #2 \q_stop { \if_int_compare:w #1 = \int_eval:w #2 \int_eval_end: \prg_return_true: \else: \prg_return_false: \fi: } \cs_new:cpn { int_compare_==:w } #1 == #2 \q_stop { \if_int_compare:w #1 = \int_eval:w #2 \int_eval_end: \prg_return_true: \else: \prg_return_false: \fi: } \cs_new:cpn { int_compare_!=:w } #1 != #2 \q_stop { \if_int_compare:w #1 = \int_eval:w #2 \int_eval_end: \prg_return_false: \else: \prg_return_true: \fi: } \cs_new:cpn { int_compare_<:w } #1 < #2 \q_stop { \if_int_compare:w #1 < \int_eval:w #2 \int_eval_end: \prg_return_true: \else: \prg_return_false: \fi: } \cs_new:cpn { int_compare_>:w } #1 > #2 \q_stop { \if_int_compare:w #1 > \int_eval:w #2 \int_eval_end: \prg_return_true: \else: \prg_return_false: \fi: } \cs_new:cpn { int_compare_<=:w } #1 <= #2 \q_stop { \if_int_compare:w #1 > \int_eval:w #2 \int_eval_end: \prg_return_false: \else: \prg_return_true: \fi: } \cs_new:cpn { int_compare_>=:w } #1 >= #2 \q_stop { \if_int_compare:w #1 < \int_eval:w #2 \int_eval_end: \prg_return_false: \else: \prg_return_true: \fi: } \prg_new_conditional:Npnn \int_compare:nNn #1#2#3 { p , T , F , TF} { \if_int_compare:w \int_eval:w #1 #2 \int_eval:w #3 \int_eval_end: \prg_return_true: \else: \prg_return_false: \fi: } \prg_new_conditional:Npnn \int_if_odd:n #1 { p , T , F , TF} { \if_int_odd:w \int_eval:w #1 \int_eval_end: \prg_return_true: \else: \prg_return_false: \fi: } \prg_new_conditional:Npnn \int_if_even:n #1 { p , T , F , TF} { \if_int_odd:w \int_eval:w #1 \int_eval_end: \prg_return_false: \else: \prg_return_true: \fi: } \cs_new:Npn \int_while_do:nn #1#2 { \int_compare:nT {#1} { #2 \int_while_do:nn {#1} {#2} } } \cs_new:Npn \int_until_do:nn #1#2 { \int_compare:nF {#1} { #2 \int_until_do:nn {#1} {#2} } } \cs_new:Npn \int_do_while:nn #1#2 { #2 \int_compare:nT {#1} { \int_do_while:nNnn {#1} {#2} } } \cs_new:Npn \int_do_until:nn #1#2 { #2 \int_compare:nF {#1} { \int_do_until:nn {#1} {#2} } } \cs_new:Npn \int_while_do:nNnn #1#2#3#4 { \int_compare:nNnT {#1} #2 {#3} { #4 \int_while_do:nNnn {#1} #2 {#3} {#4} } } \cs_new:Npn \int_until_do:nNnn #1#2#3#4 { \int_compare:nNnF {#1} #2 {#3} { #4 \int_until_do:nNnn {#1} #2 {#3} {#4} } } \cs_new:Npn \int_do_while:nNnn #1#2#3#4 { #4 \int_compare:nNnT {#1} #2 {#3} { \int_do_while:nNnn {#1} #2 {#3} {#4} } } \cs_new:Npn \int_do_until:nNnn #1#2#3#4 { #4 \int_compare:nNnF {#1} #2 {#3} { \int_do_until:nNnn {#1} #2 {#3} {#4} } } \cs_new_nopar:Npn \int_to_arabic:n #1 { \int_eval:n {#1} } \cs_new_nopar:Npn \int_to_symbols:nnn #1#2#3 { \int_compare:nNnTF {#1} > {#2} { \exp_args:Nf \int_to_symbols:nnn { \int_div_truncate:nn { #1 - 1 } {#2} } {#2} {#3} \exp_args:Nf \prg_case_int:nnn { \int_eval:n { 1 + \int_mod:nn { #1 - 1 } {#2} } } {#3} { } } { \exp_args:Nf \prg_case_int:nnn { \int_eval:n {#1} } {#3} { } } } \cs_new:Npn \int_to_alph:n #1 { \int_to_symbols:nnn {#1} { 26 } { { 1 } { a } { 2 } { b } { 3 } { c } { 4 } { d } { 5 } { e } { 6 } { f } { 7 } { g } { 8 } { h } { 9 } { i } { 10 } { j } { 11 } { k } { 12 } { l } { 13 } { m } { 14 } { n } { 15 } { o } { 16 } { p } { 17 } { q } { 18 } { r } { 19 } { s } { 20 } { t } { 21 } { u } { 22 } { v } { 23 } { w } { 24 } { x } { 25 } { y } { 26 } { z } } } \cs_new:Npn \int_to_Alph:n #1 { \int_to_symbols:nnn {#1} { 26 } { { 1 } { A } { 2 } { B } { 3 } { C } { 4 } { D } { 5 } { E } { 6 } { F } { 7 } { G } { 8 } { H } { 9 } { I } { 10 } { J } { 11 } { K } { 12 } { L } { 13 } { M } { 14 } { N } { 15 } { O } { 16 } { P } { 17 } { Q } { 18 } { R } { 19 } { S } { 20 } { T } { 21 } { U } { 22 } { V } { 23 } { W } { 24 } { X } { 25 } { Y } { 26 } { Z } } } \cs_new:Npn \int_to_base:nn #1 { \exp_args:Nf \int_to_base_aux_i:nn { \int_eval:n {#1} } } \cs_new:Npn \int_to_base_aux_i:nn #1#2 { \int_compare:nNnTF {#1} < \c_zero { \exp_args:No \int_to_base_aux_ii:nnN { \use_none:n #1 } {#2} - } { \int_to_base_aux_ii:nnN {#1} {#2} \c_empty_tl } } \cs_new:Npn \int_to_base_aux_ii:nnN #1#2#3 { \int_compare:nNnTF {#1} < {#2} { \exp_last_unbraced:Nf #3 { \int_to_letter:n {#1} } } { \exp_args:Nf \int_to_base_aux_iii:nnnN { \int_to_letter:n { \int_mod:nn {#1} {#2} } } {#1} {#2} #3 } } \cs_new:Npn \int_to_base_aux_iii:nnnN #1#2#3#4 { \exp_args:Nf \int_to_base_aux_ii:nnN { \int_div_truncate:nn {#2} {#3} } {#3} #4 #1 } \cs_new:Npn \int_to_letter:n #1 { \exp_after:wN \exp_after:wN \if_case:w \int_eval:w #1 - \c_ten \int_eval_end: 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 \else: #1 \fi: } \cs_new:Npn \int_to_binary:n #1 { \int_to_base:nn {#1} { 2 } } \cs_new:Npn \int_to_hexadecimal:n #1 { \int_to_base:nn {#1} { 16 } } \cs_new:Npn \int_to_octal:n #1 { \int_to_base:nn {#1} { 8 } } \cs_new_nopar:Npn \int_to_roman:n #1 { \exp_after:wN \int_to_roman_aux:N \int_to_roman:w \int_eval:n {#1} Q } \cs_new_nopar:Npn \int_to_roman_aux:N #1 { \use:c { int_to_roman_ #1 :w } \int_to_roman_aux:N } \cs_new_nopar:Npn \int_to_Roman:n #1 { \exp_after:wN \int_to_Roman_aux:N \int_to_roman:w \int_eval:n {#1} Q } \cs_new_nopar:Npn \int_to_Roman_aux:N #1 { \use:c { int_to_Roman_ #1 :w } \int_to_Roman_aux:N } \cs_new_nopar:Npn \int_to_roman_i:w { i } \cs_new_nopar:Npn \int_to_roman_v:w { v } \cs_new_nopar:Npn \int_to_roman_x:w { x } \cs_new_nopar:Npn \int_to_roman_l:w { l } \cs_new_nopar:Npn \int_to_roman_c:w { c } \cs_new_nopar:Npn \int_to_roman_d:w { d } \cs_new_nopar:Npn \int_to_roman_m:w { m } \cs_new_nopar:Npn \int_to_roman_Q:w #1 { } \cs_new_nopar:Npn \int_to_Roman_i:w { I } \cs_new_nopar:Npn \int_to_Roman_v:w { V } \cs_new_nopar:Npn \int_to_Roman_x:w { X } \cs_new_nopar:Npn \int_to_Roman_l:w { L } \cs_new_nopar:Npn \int_to_Roman_c:w { C } \cs_new_nopar:Npn \int_to_Roman_d:w { D } \cs_new_nopar:Npn \int_to_Roman_m:w { M } \cs_new_nopar:Npn \int_to_Roman_Q:w #1 { } \cs_new:Npn \int_get_sign:n #1 { \int_get_sign_and_digits_aux:nNNN {#1} \c_true_bool \c_true_bool \c_false_bool } \cs_new:Npn \int_get_digits:n #1 { \int_get_sign_and_digits_aux:nNNN {#1} \c_true_bool \c_false_bool \c_true_bool } \cs_new:Npn \int_get_sign_and_digits_aux:nNNN #1#2#3#4 { \exp_args:Nf \tl_if_head_eq_charcode:nNTF {#1} - { \bool_if:NTF #2 { \int_get_sign_and_digits_aux:oNNN { \use_none:n #1 } \c_false_bool #3#4 } { \int_get_sign_and_digits_aux:oNNN { \use_none:n #1 } \c_true_bool #3#4 } } { \exp_args:Nf \tl_if_head_eq_charcode:nNTF {#1} + { \int_get_sign_and_digits_aux:oNNN { \use_none:n #1 } #2#3#4 } { \bool_if:NT #3 { \bool_if:NF #2 - } \bool_if:NT #4 {#1} } } } \cs_generate_variant:Nn \int_get_sign_and_digits_aux:nNNN { o } \cs_new:Npn \int_from_alph:n #1 { \int_eval:n { \int_get_sign:n {#1} \exp_args:Nf \int_from_alph_aux:n { \int_get_digits:n {#1} } } } \cs_new:Npn \int_from_alph_aux:n #1 { \int_from_alph_aux:nN { 0 } #1 \q_nil } \cs_new:Npn \int_from_alph_aux:nN #1#2 { \quark_if_nil:NTF #2 {#1} { \exp_args:Nf \int_from_alph_aux:nN { \int_eval:n { #1 * 26 + \int_from_alph_aux:N #2 } } } } \cs_new:Npn \int_from_alph_aux:N #1 { \int_eval:n { `#1 - \int_compare:nNnTF { `#1 } < { 91 } { 64 } { 96 } } } \cs_new:Npn \int_from_base:nn #1#2 { \int_eval:n { \int_get_sign:n {#1} \exp_args:Nf \int_from_base_aux:nn { \int_get_digits:n {#1} } {#2} } } \cs_new:Npn \int_from_base_aux:nn #1#2 { \int_from_base_aux:nnN { 0 } { #2 } #1 \q_nil } \cs_new:Npn \int_from_base_aux:nnN #1#2#3 { \quark_if_nil:NTF #3 {#1} { \exp_args:Nf \int_from_base_aux:nnN { \int_eval:n { #1 * #2 + \int_from_base_aux:N #3 } } {#2} } } \cs_new:Npn \int_from_base_aux:N #1 { \int_compare:nNnTF { `#1 } < { 58 } {#1} { \int_eval:n { `#1 - \int_compare:nNnTF { `#1 } < { 91 } { 55 } { 87 } } } } \cs_new:Npn \int_from_binary:n #1 { \int_from_base:nn {#1} \c_two } \cs_new:Npn \int_from_hexadecimal:n #1 { \int_from_base:nn {#1} \c_sixteen } \cs_new:Npn \int_from_octal:n #1 { \int_from_base:nn {#1} \c_eight } \int_const:cn { c_int_from_roman_i_int } { 1 } \int_const:cn { c_int_from_roman_v_int } { 5 } \int_const:cn { c_int_from_roman_x_int } { 10 } \int_const:cn { c_int_from_roman_l_int } { 50 } \int_const:cn { c_int_from_roman_c_int } { 100 } \int_const:cn { c_int_from_roman_d_int } { 500 } \int_const:cn { c_int_from_roman_m_int } { 1000 } \int_const:cn { c_int_from_roman_I_int } { 1 } \int_const:cn { c_int_from_roman_V_int } { 5 } \int_const:cn { c_int_from_roman_X_int } { 10 } \int_const:cn { c_int_from_roman_L_int } { 50 } \int_const:cn { c_int_from_roman_C_int } { 100 } \int_const:cn { c_int_from_roman_D_int } { 500 } \int_const:cn { c_int_from_roman_M_int } { 1000 } \cs_new_nopar:Npn \int_from_roman:n #1 { \tl_if_blank:nF {#1} { \exp_after:wN \int_from_roman_end:w \int_value:w \int_eval:w \int_from_roman_aux:NN #1 Q \q_stop } } \cs_new_nopar:Npn \int_from_roman_aux:NN #1#2 { \str_if_eq:nnTF {#1} { Q } {#1#2} { \str_if_eq:nnTF {#2} { Q } { \cs_if_exist:cF { c_int_from_roman_ #1 _int } { \int_from_roman_clean_up:w } + \use:c { c_int_from_roman_ #1 _int } #2 } { \cs_if_exist:cF { c_int_from_roman_ #1 _int } { \int_from_roman_clean_up:w } \cs_if_exist:cF { c_int_from_roman_ #2 _int } { \int_from_roman_clean_up:w } \int_compare:nNnTF { \use:c { c_int_from_roman_ #1 _int } } < { \use:c { c_int_from_roman_ #2 _int } } { + \use:c { c_int_from_roman_ #2 _int } - \use:c { c_int_from_roman_ #1 _int } \int_from_roman_aux:NN } { + \use:c { c_int_from_roman_ #1 _int } \int_from_roman_aux:NN #2 } } } } \cs_new_nopar:Npn \int_from_roman_end:w #1 Q #2 \q_stop { \tl_if_empty:nTF {#2} {#1} {#2} } \cs_new_nopar:Npn \int_from_roman_clean_up:w #1 Q { + 0 Q -1 } \cs_new_eq:NN \int_show:N \kernel_register_show:N \cs_new_eq:NN \int_show:c \kernel_register_show:c \int_const:Nn \c_one { 1 } \int_const:Nn \c_two { 2 } \int_const:Nn \c_three { 3 } \int_const:Nn \c_four { 4 } \int_const:Nn \c_five { 5 } \int_const:Nn \c_eight { 8 } \int_const:Nn \c_nine { 9 } \int_const:Nn \c_ten { 10 } \int_const:Nn \c_eleven { 11 } \int_const:Nn \c_thirteen { 13 } \int_const:Nn \c_fourteen { 14 } \int_const:Nn \c_fifteen { 15 } \int_const:Nn \c_thirty_two { 32 } \int_const:Nn \c_two_hundred_fifty_five { 255 } \int_const:Nn \c_two_hundred_fifty_six { 256 } \int_const:Nn \c_one_hundred { 100 } \int_const:Nn \c_one_thousand { 1000 } \int_const:Nn \c_ten_thousand { 10000 } \int_const:Nn \c_max_int { 2 147 483 647 } \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 \g_seq_nesting_depth_int \int_new:N \g_tl_inline_level_int \cs_new_eq:NN \int_convert_from_base_ten:nn \int_to_base:nn \cs_new_eq:NN \int_convert_to_symbols:nnn \int_to_symbols:nnn \cs_new_eq:NN \int_convert_to_base_ten:nn \int_from_base:nn \cs_new_nopar:Npn \int_to_symbol:n { \mode_if_math:TF { \int_to_symbol_math:n } { \int_to_symbol_text:n } } \cs_new:Npn \int_to_symbol_math:n #1 { \int_to_symbols:nnn {#1} { 9 } { { 1 } { * } { 2 } { \dagger } { 3 } { \ddagger } { 4 } { \mathsection } { 5 } { \mathparagraph } { 6 } { \| } { 7 } { ** } { 8 } { \dagger \dagger } { 9 } { \ddagger \ddagger } } } \cs_new:Npn \int_to_symbol_text:n #1 { \int_to_symbols:nnn {#1} { 9 } { { 1 } { \textasteriskcentered } { 2 } { \textdagger } { 3 } { \textdaggerdbl } { 4 } { \textsection } { 5 } { \textparagraph } { 6 } { \textbardbl } { 7 } { \textasteriskcentered \textasteriskcentered } { 8 } { \textdagger \textdagger } { 9 } { \textdaggerdbl \textdaggerdbl } } } %% %% %% End of file `l3int.sty'.