diff options
author | Karl Berry <karl@freefriends.org> | 2007-05-22 17:46:23 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2007-05-22 17:46:23 +0000 |
commit | f4eb27d3314d15838f674a3872000159d029f88b (patch) | |
tree | 6e9ab33c5a2d702912b4a969ade4e4e2ac586d62 /Master/texmf-dist/tex/latex/expl3/l3int.sty | |
parent | 14af3f447439750920f754792b89f113d019076a (diff) |
update expl3
git-svn-id: svn://tug.org/texlive/trunk@4335 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/expl3/l3int.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/expl3/l3int.sty | 358 |
1 files changed, 293 insertions, 65 deletions
diff --git a/Master/texmf-dist/tex/latex/expl3/l3int.sty b/Master/texmf-dist/tex/latex/expl3/l3int.sty index e745beceb25..cbbfa2e9590 100644 --- a/Master/texmf-dist/tex/latex/expl3/l3int.sty +++ b/Master/texmf-dist/tex/latex/expl3/l3int.sty @@ -15,14 +15,49 @@ %% Do not distribute a modified version of this file. %% %% -%% File: l3int.dtx Copyright (C) 1990-1998 LaTeX3 project -\NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{l3int} - [1998/04/20 v1.0c L3 Experimental Integer module] -\RequirePackage{l3basics}\par -\def_new:Npn \int_incr:N #1{\tex_advance:D#1\c_one +%% File: l3int.dtx Copyright (C) 1990-2006 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 573 2006-08-21 20:59:37Z morten $ + {L3 Experimental Integer module} + +\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{\tex_advance:D#1\c_minus_one +\def_new:Npn \int_decr:N #1{\int_advance:w#1\c_minus_one } \def_new:Npn \int_gincr:N { \pref_global:D @@ -34,22 +69,25 @@ \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_new:Npn \int_new:N {} % but since we don't distribute -\let:NN \int_new:N \newcount % allocation better nick the LaTeX one ... +\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#2\scan_stop: +\def_new:Npn \int_set:Nn #1#2{#1 \int_eval:w #2\scan_stop: } \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{ - \tex_advance:D#1#2\scan_stop: + \int_advance:w #1 by \int_eval:w #2\scan_stop: } \def_new:Npn\int_add:cn{\exp_args:Nc\int_add:Nn} \def_new:Npn \int_sub:Nn #1#2{ - \tex_advance:D#1-#2\scan_stop: + \int_advance:w #1-\int_eval:w #2\scan_stop: } \def_new:Npn \int_gadd:Nn { \pref_global:D @@ -59,68 +97,258 @@ \int_sub: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_gincr:c {\exp_args:Nc \int_gincr:N} \def_new:Npn \int_gdecr:c {\exp_args:Nc \int_gdecr:N} -\chk_new_cs:N \l_tmpa_int -\tex_countdef:D\l_tmpa_int 255 +\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_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 -\tex_chardef:D \c_zero = 0 \scan_stop: -\tex_chardef:D \c_one = 1 \scan_stop: -\tex_chardef:D \c_two = 2 \scan_stop: -\tex_chardef:D \c_three = 3 \scan_stop: -\tex_chardef:D \c_four = 4 \scan_stop: -\tex_chardef:D \c_sixteen = 16 \scan_stop: -\tex_chardef:D \c_thirty_two = 32 \scan_stop: -\tex_chardef:D \c_twohundred_fifty_five = 255 \scan_stop: -\tex_mathchardef:D \c_twohundred_fifty_six = 256 \scan_stop: -\tex_mathchardef:D \c_thousand = 1000 \scan_stop: -\tex_mathchardef:D \c_ten_thousand = 10000 \scan_stop: -\tex_mathchardef:D \c_ten_thousand_one = 10001 \scan_stop: -\tex_mathchardef:D \c_ten_thousand_two = 10002 \scan_stop: -\tex_mathchardef:D \c_ten_thousand_three = 10003 \scan_stop: -\tex_mathchardef:D \c_ten_thousand_four = 10004 \scan_stop: -\tex_mathchardef:D \c_twenty_thousand = 20000 \scan_stop: -\let_new:NN \fint_new:N \newmuskip % nicked from LaTeX -\def_new:Npn \fint_use:N {\exp_after:NN\fint_use_aux:w\the_internal:D} -\tex_lccode:D`\!=`\m \tex_lccode:D`\?=`\u -\tex_lowercase:D{\def_new:Npn \fint_use_aux:w #1.0!?{#1}} -\tex_lccode:D`\!=0\scan_stop: \tex_lccode:D`\?=0\scan_stop: -\def_new:Npn \fint_set:Nn #1#2{#1#2~mu\scan_stop: -} -\def_new:Npn \fint_gset:Nn{ - \pref_global:D - \fint_set:Nn} -\def_new:Npn \fint_set_eq:NN #1#2{#1#2 +\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 +\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 \fint_gset_eq:NN { - \pref_global:D - \fint_set_eq:NN} -\def_new:Npn \fint_add:Nn #1#2{\int_add:Nn#1{#2mu}} -\def_new:Npn \fint_gadd:Nn { - \pref_global:D - \fint_add:Nn} -\def_new:Npn \fint_sub:Nn #1#2{\int_sub:Nn#1{#2mu}} -\def_new:Npn \fint_gsub:Nn { - \pref_global:D - \fint_sub:Nn} -\def_new:Npn \fint_incr:N #1{\advance:D#1\c_one mu\scan_stop: +\def_new:Npn \int_div_truncate:nn { + \int_pre_eval_two_args:Nnn\int_div_truncate_raw:nn } -\def_new:Npn \fint_decr:N #1{\advance:D#1\c_minus_one mu\scan_stop: +\def_new:Npn \int_div_truncate_raw:nn #1#2 { + \int_eval:n{ (2*#1 - #2) / (2* #2) } +} +\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_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_new:Npn \int_whiledo:nNnT #1#2#3#4{ + \int_compare:nNnT {#1}#2{#3}{#4 \int_whiledo:nNnT {#1}#2{#3}{#4}} +} +\def_new:Npn \int_whiledo:nNnF #1#2#3#4{ + \int_compare:nNnF {#1}#2{#3}{#4 \int_whiledo:nNnF {#1}#2{#3}{#4}} +} +\def_new:Npn \int_dowhile:nNnT #1#2#3#4{ + #4 \int_compare:nNnT {#1}#2{#3}{\int_dowhile:nNnT {#1}#2{#3}{#4}} +} +\def_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: + } + } } -\def_new:Npn \fint_gincr:N { - \pref_global:D - \fint_incr:N} -\def_new:Npn \fint_gdecr:N { - \pref_global:D - \fint_decr:N} -\def:Npn \fint_incr:N #1{\fint_add:Nn#1\c_one} -\def:Npn \fint_decr:N #1{\fint_add:Nn#1\c_minus_one} -\tex_mathchardef:D\c_fint_max=16383 \scan_stop: - %% %% %% End of file `l3int.sty'. |