From 29c459636115f7de4ae9a8681927b52a1e896805 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Tue, 28 Feb 2012 00:40:51 +0000
Subject: l3kernel 3471 (26feb12)

git-svn-id: svn://tug.org/texlive/trunk@25525 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/source/latex/l3kernel/l3int.dtx | 87 ++++++++++++-----------
 1 file changed, 47 insertions(+), 40 deletions(-)

(limited to 'Master/texmf-dist/source/latex/l3kernel/l3int.dtx')

diff --git a/Master/texmf-dist/source/latex/l3kernel/l3int.dtx b/Master/texmf-dist/source/latex/l3kernel/l3int.dtx
index f977f49c9f8..fa633515f99 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{l3names}
-\GetIdInfo$Id: l3int.dtx 3315 2012-02-06 11:17:04Z bruno $
+\GetIdInfo$Id: l3int.dtx 3460 2012-02-26 12:16:41Z will $
   {L3 Experimental integers}
 %</driver|package>
 %<*driver>
@@ -117,7 +117,7 @@
 %
 % \begin{function}[EXP]{\int_div_round:nn}
 %   \begin{syntax}
-%     \cs{int_div_round:nn} \Arg{intexpr1} \Arg{intexpr2}
+%     \cs{int_div_round:nn} \Arg{intexpr_1} \Arg{intexpr_2}
 %   \end{syntax}
 %   Evaluates the two \meta{integer expressions} as described earlier,
 %   then calculates the result of dividing the first value by the
@@ -127,9 +127,9 @@
 %   the input stream as a \meta{integer denotation} after two expansions.
 % \end{function}
 %
-% \begin{function}[EXP]{\int_div_truncate:nn}
+% \begin{function}[EXP, updated = 2012-02-09]{\int_div_truncate:nn}
 %   \begin{syntax}
-%     \cs{int_div_truncate:nn} \Arg{intexpr1} \Arg{intexpr2}
+%     \cs{int_div_truncate:nn} \Arg{intexpr_1} \Arg{intexpr_2}
 %   \end{syntax}
 %   Evaluates the two \meta{integer expressions} as described earlier,
 %   then calculates the result of dividing the first value by the
@@ -140,8 +140,8 @@
 %
 % \begin{function}[EXP]{\int_max:nn, \int_min:nn}
 %   \begin{syntax}
-%     \cs{int_max:nn} \Arg{intexpr1} \Arg{intexpr2}
-%     \cs{int_min:nn} \Arg{intexpr1} \Arg{intexpr2}
+%     \cs{int_max:nn} \Arg{intexpr_1} \Arg{intexpr_2}
+%     \cs{int_min:nn} \Arg{intexpr_1} \Arg{intexpr_2}
 %   \end{syntax}
 %   Evaluates the \meta{integer expressions} as described for
 %   \cs{int_eval:n} and leaves either the larger or smaller value
@@ -151,7 +151,7 @@
 %
 % \begin{function}[EXP]{\int_mod:nn}
 %   \begin{syntax}
-%     \cs{int_mod:nn} \Arg{intexpr1} \Arg{intexpr2}
+%     \cs{int_mod:nn} \Arg{intexpr_1} \Arg{intexpr_2}
 %   \end{syntax}
 %   Evaluates the two \meta{integer expressions} as described earlier,
 %   then calculates the integer remainder of dividing the first
@@ -273,9 +273,9 @@
 %
 % \begin{function}[EXP,pTF]{\int_compare:nNn}
 %   \begin{syntax}
-%     \cs{int_compare_p:nNn} \Arg{intexpr1} \meta{relation} \Arg{intexpr2} \\
+%     \cs{int_compare_p:nNn} \Arg{intexpr_1} \meta{relation} \Arg{intexpr_2} \\
 %     \cs{int_compare:nNnTF}
-%     ~~\Arg{intexpr1} \meta{relation} \Arg{intexpr2}
+%     ~~\Arg{intexpr_1} \meta{relation} \Arg{intexpr_2}
 %     ~~\Arg{true code} \Arg{false code}
 %   \end{syntax}
 %   This function first evaluates each of the \meta{integer expressions}
@@ -328,7 +328,7 @@
 % \begin{function}[rEXP]{\int_do_while:nNnn}
 %   \begin{syntax}
 %      \cs{int_do_while:nNnn}
-%      ~~\Arg{intexpr1} \meta{relation} \Arg{intexpr2} \Arg{code}
+%      ~~\Arg{intexpr_1} \meta{relation} \Arg{intexpr_2} \Arg{code}
 %   \end{syntax}
 %   Evaluates the relationship between the two \meta{integer expressions}
 %   as described for \cs{int_compare:nNnTF}, and then places the
@@ -341,7 +341,7 @@
 % \begin{function}[rEXP]{\int_do_until:nNnn}
 %   \begin{syntax}
 %      \cs{int_do_until:nNnn}
-%      ~~\Arg{intexpr1} \meta{relation} \Arg{intexpr2} \Arg{code}
+%      ~~\Arg{intexpr_1} \meta{relation} \Arg{intexpr_2} \Arg{code}
 %   \end{syntax}
 %   Evaluates the relationship between the two \meta{integer expressions}
 %   as described for \cs{int_compare:nNnTF}, and then places the
@@ -354,7 +354,7 @@
 % \begin{function}[rEXP]{\int_until_do:nNnn}
 %   \begin{syntax}
 %      \cs{int_until_do:nNnn}
-%      ~~\Arg{intexpr1} \meta{relation} \Arg{intexpr2} \Arg{code}
+%      ~~\Arg{intexpr_1} \meta{relation} \Arg{intexpr_2} \Arg{code}
 %   \end{syntax}
 %   Places the \meta{code} in the input stream for \TeX{} to process, and
 %   then evaluates the relationship between the two
@@ -367,7 +367,7 @@
 % \begin{function}[rEXP]{\int_while_do:nNnn}
 %   \begin{syntax}
 %      \cs{int_while_do:nNnn} \
-%      ~~\Arg{intexpr1} \meta{relation} \Arg{intexpr2} \Arg{code}
+%      ~~\Arg{intexpr_1} \meta{relation} \Arg{intexpr_2} \Arg{code}
 %   \end{syntax}
 %   Places the \meta{code} in the input stream for \TeX{} to process, and
 %   then evaluates the relationship between the two
@@ -916,41 +916,47 @@
 % \end{macro}
 % \end{macro}
 %
-% \begin{macro}{\int_div_truncate:nn}
+% \begin{macro}[EXP]{\int_div_truncate:nn}
 % \UnitTested
-% \begin{macro}{\int_div_round:nn}
+% \begin{macro}[EXP]{\int_div_round:nn}
 % \UnitTested
-% \begin{macro}{\int_mod:nn}
+% \begin{macro}[EXP]{\int_mod:nn}
 % \UnitTested
-%   As \cs{int_eval:w} rounds the result of a division we also
-%   provide a version that truncates the result. This version is thanks
-%   to Heiko Oberdiek: getting things right in all cases is not so easy.
+% \begin{macro}[aux, EXP]{\int_div_truncate_aux:NwNw}
+%   As \cs{int_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
+%   handy when those are more expressions are expensive to evaluate
+%   (\emph{e.g.}, \cs{tl_length:n}). If the numerator |#1#2| is $0$,
+%   then we divide $0$ by the denominator (this ensures that $0/0$ is
+%   correctly reported as an error). Otherwise, shift the numerator
+%   |#1#2| towards $0$ by $(\left\vert\texttt{\#3\#4}\right\vert-1)/2$, which we
+%   round away from zero. It turns out that this quantity exactly
+%   compensates the difference between \eTeX{}'s rounding and the
+%   truncating behaviour that we want. The details are thanks to Heiko
+%   Oberdiek: getting things right in all cases is not so easy.
 %    \begin{macrocode}
 \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_use:N \int_eval:w
+      \exp_after:wN \int_div_truncate_aux:NwNw
+      \int_use:N \int_eval:w #1 \exp_after:wN ;
+      \int_use:N \int_eval:w #2 ;
     \int_eval_end:
   }
+\cs_new:Npn \int_div_truncate_aux:NwNw #1#2; #3#4;
+  {
+    \if_meaning:w 0 #1
+      \c_zero
+    \else:
+      (
+        #1#2
+        \if_meaning:w - #1 + \else: - \fi:
+        ( \if_meaning:w - #3 - \fi: #3#4 - \c_one ) / \c_two
+      )
+    \fi:
+    / #3#4
+  }
 %    \end{macrocode}
 %   For the sake of completeness:
 %    \begin{macrocode}
@@ -968,6 +974,7 @@
 % \end{macro}
 % \end{macro}
 % \end{macro}
+% \end{macro}
 %
 % \subsection{Creating and initialising integers}
 %
-- 
cgit v1.2.3

