summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3kernel/l3int.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3int.dtx')
-rw-r--r--Master/texmf-dist/source/latex/l3kernel/l3int.dtx86
1 files changed, 50 insertions, 36 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3int.dtx b/Master/texmf-dist/source/latex/l3kernel/l3int.dtx
index 7a176c93588..e67616a2f7d 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3int.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3int.dtx
@@ -35,7 +35,7 @@
%
%<*driver|package>
\RequirePackage{l3bootstrap}
-\GetIdInfo$Id: l3int.dtx 4121 2012-08-17 01:36:30Z bruno $
+\GetIdInfo$Id: l3int.dtx 4237 2012-09-26 10:18:58Z bruno $
{L3 Integers}
%</driver|package>
%<*driver>
@@ -93,7 +93,7 @@
% \tl_new:N \l_my_tl
% \tl_set:Nn \l_my_tl { 5 }
% \int_new:N \l_my_int
-% \int\set:Nn \l_my_int { 4 }
+% \int_set:Nn \l_my_int { 4 }
% \int_eval:n { \l_my_tl + \l_my_int * 3 - ( 3 + 4 * 5 ) }
% \end{verbatim}
% both evaluate to \( -6 \). The \Arg{integer expression} may
@@ -105,7 +105,7 @@
% suitable termination if used in a \TeX{}-style integer assignment.
% \end{function}
%
-% \begin{function}[EXP]{\int_abs:n}
+% \begin{function}[EXP, updated = 2012-09-26]{\int_abs:n}
% \begin{syntax}
% \cs{int_abs:n} \Arg{integer expression}
% \end{syntax}
@@ -115,7 +115,7 @@
% expansions.
% \end{function}
%
-% \begin{function}[EXP]{\int_div_round:nn}
+% \begin{function}[EXP, updated = 2012-09-26]{\int_div_round:nn}
% \begin{syntax}
% \cs{int_div_round:nn} \Arg{intexpr_1} \Arg{intexpr_2}
% \end{syntax}
@@ -138,7 +138,7 @@
% \meta{integer denotation} after two expansions.
% \end{function}
%
-% \begin{function}[EXP]{\int_max:nn, \int_min:nn}
+% \begin{function}[EXP, updated = 2012-09-26]{\int_max:nn, \int_min:nn}
% \begin{syntax}
% \cs{int_max:nn} \Arg{intexpr_1} \Arg{intexpr_2}
% \cs{int_min:nn} \Arg{intexpr_1} \Arg{intexpr_2}
@@ -149,7 +149,7 @@
% expansions.
% \end{function}
%
-% \begin{function}[EXP]{\int_mod:nn}
+% \begin{function}[EXP, updated = 2012-09-26]{\int_mod:nn}
% \begin{syntax}
% \cs{int_mod:nn} \Arg{intexpr_1} \Arg{intexpr_2}
% \end{syntax}
@@ -941,48 +941,56 @@
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{\int_max:nn}
+% \begin{macro}[EXP]{\int_abs:n}
+% \begin{macro}[aux, EXP]{\@@_abs:N}
% \UnitTested
-% \begin{macro}{\int_min:nn}
+% \begin{macro}[EXP]{\int_max:nn}
+% \begin{macro}[EXP]{\int_min:nn}
+% \begin{macro}[aux, EXP]{\@@_maxmin:wwN}
% \UnitTested
-% \begin{macro}{\int_abs:n}
% \UnitTested
-% Functions for $\min$, $\max$, and absolute value.
+% Functions for $\min$, $\max$, and absolute value with only one
+% evaluation. The absolute value is obtained by removing a leading
+% sign if any. All three functions expand in two steps.
% \begin{macrocode}
\cs_new:Npn \int_abs:n #1
{
- \@@_value:w
- \if_int_compare:w \@@_eval:w #1 < \c_zero
- -
- \fi:
- \@@_eval:w #1 \@@_eval_end:
+ \@@_value:w \exp_after:wN \@@_abs:N
+ \int_use:N \@@_eval:w #1 \@@_eval_end:
+ \exp_stop_f:
}
-\cs_new:Npn \int_max:nn #1#2
+\cs_new:Npn \@@_abs:N #1
+ { \if_meaning:w - #1 \else: \exp_after:wN #1 \fi: }
+\cs_set:Npn \int_max:nn #1#2
{
- \@@_value:w \@@_eval:w
- \if_int_compare:w
- \@@_eval:w #1 > \@@_eval:w #2 \@@_eval_end:
- #1
- \else:
- #2
- \fi:
- \@@_eval_end:
+ \@@_value:w \exp_after:wN \@@_maxmin:wwN
+ \int_use:N \@@_eval:w #1 \exp_after:wN ;
+ \int_use:N \@@_eval:w #2 ;
+ >
+ \exp_stop_f:
}
-\cs_new:Npn \int_min:nn #1#2
+\cs_set:Npn \int_min:nn #1#2
{
- \@@_value:w \@@_eval:w
- \if_int_compare:w
- \@@_eval:w #1 < \@@_eval:w #2 \@@_eval_end:
- #1
- \else:
- #2
- \fi:
- \@@_eval_end:
+ \@@_value:w \exp_after:wN \@@_maxmin:wwN
+ \int_use:N \@@_eval:w #1 \exp_after:wN ;
+ \int_use:N \@@_eval:w #2 ;
+ <
+ \exp_stop_f:
+ }
+\cs_new:Npn \@@_maxmin:wwN #1 ; #2 ; #3
+ {
+ \if_int_compare:w #1 #3 #2 ~
+ #1
+ \else:
+ #2
+ \fi:
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
+% \end{macro}
%
% \begin{macro}[EXP]{\int_div_truncate:nn}
% \UnitTested
@@ -991,6 +999,7 @@
% \begin{macro}[EXP]{\int_mod:nn}
% \UnitTested
% \begin{macro}[aux, EXP]{\@@_div_truncate:NwNw}
+% \begin{macro}[aux, EXP]{\@@_mod:ww}
% As \cs{@@_eval:w} rounds the result of a division we also provide a
% version that truncates the result. We use an auxiliary to make sure
% numerator and denominator are only evaluated once: this comes in
@@ -1028,21 +1037,26 @@
% \end{macrocode}
% For the sake of completeness:
% \begin{macrocode}
-\cs_new:Npn \int_div_round:nn #1#2 { \int_eval:n { ( #1 ) / ( #2 ) } }
+\cs_new:Npn \int_div_round:nn #1#2
+ { \@@_value:w \@@_eval:w ( #1 ) / ( #2 ) \@@_eval_end: }
% \end{macrocode}
% Finally there's the modulus operation.
% \begin{macrocode}
\cs_new:Npn \int_mod:nn #1#2
{
- \@@_value:w \@@_eval:w
- #1 - \int_div_truncate:nn {#1} {#2} * ( #2 )
+ \@@_value:w \@@_eval:w \exp_after:wN \@@_mod:ww
+ \@@_value:w \@@_eval:w #1 \exp_after:wN ;
+ \@@_value:w \@@_eval:w #2 ;
\@@_eval_end:
}
+\cs_new:Npn \@@_mod:ww #1; #2;
+ { #1 - ( \@@_div_truncate:NwNw #1 ; #2 ; ) * #2 }
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
%
% \subsection{Creating and initialising integers}
%