summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx')
-rw-r--r--Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx96
1 files changed, 52 insertions, 44 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx b/Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx
index 9f9e0d0f352..31a0ba85783 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx
@@ -22,7 +22,7 @@
%
%<*driver>
\documentclass[full]{l3doc}
-\GetIdInfo$Id: l3fp-round.dtx 6805 2016-12-28 22:15:52Z joseph $
+\GetIdInfo$Id: l3fp-round.dtx 6968 2017-02-20 16:08:44Z bruno $
{L3 Floating-point rounding}
\begin{document}
\DocInput{\jobname.dtx}
@@ -73,6 +73,14 @@
%
% \subsection{Rounding tools}
%
+% \begin{variable}{\c_@@_five_int}
+% This is used as the half-point for which numbers are rounded
+% up/down.
+% \begin{macrocode}
+\int_const:Nn \c_@@_five_int { 5 }
+% \end{macrocode}
+% \end{variable}
+%
% Floating point operations often yield a result that cannot be exactly
% represented in a significand with $16$ digits. In that case, we need to
% round the exact result to a representable number. The \textsc{ieee}
@@ -98,16 +106,16 @@
% (but there is not interface for that yet).
%
% The rounding tools available in this module are many variations on a
-% base function \cs{@@_round:NNN}, which expands to \cs{c_zero} or
-% \cs{c_one} depending on whether the final result should be rounded up
+% base function \cs{@@_round:NNN}, which expands to |0\exp_stop_f:| or
+% |1\exp_stop_f:| depending on whether the final result should be rounded up
% or down.
% \begin{itemize}
% \item \cs{@@_round:NNN} \meta{sign} \meta{digit_1} \meta{digit_2}
-% can expand to \cs{c_zero} or \cs{c_one}.
+% can expand to |0\exp_stop_f:| or |1\exp_stop_f:|.
% \item \cs{@@_round_s:NNNw} \meta{sign} \meta{digit_1} \meta{digit_2}
-% \meta{more digits}|;| can expand to |\c_zero ;| or |\c_one ;|.
+% \meta{more digits}|;| can expand to |0\exp_stop_f:;| or |1\exp_stop_f:;|.
% \item \cs{@@_round_neg:NNN} \meta{sign} \meta{digit_1} \meta{digit_2}
-% can expand to \cs{c_zero} or \cs{c_one}.
+% can expand to |0\exp_stop_f:| or |1\exp_stop_f:|.
% \end{itemize}
% See implementation comments for details on the syntax.
%
@@ -127,8 +135,8 @@
% \end{syntax}
% If rounding the number $\meta{final sign}
% \meta{digit_1}.\meta{digit_2}$ to an integer rounds it towards zero
-% (truncates it), this function expands to \cs{c_zero}, and otherwise
-% to \cs{c_one}. Typically used within the scope of an
+% (truncates it), this function expands to |0\exp_stop_f:|, and otherwise
+% to |1\exp_stop_f:|. Typically used within the scope of an
% \cs{__int_eval:w}, to add~$1$ if needed, and thereby round
% correctly. The result depends on the rounding mode.
%
@@ -137,9 +145,9 @@
% rounding towards~$-\infty$ or towards~$+\infty$. Also recall that
% \meta{final sign} is~$0$ for positive, and~$2$ for negative.
%
-% By default, the functions below return \cs{c_zero}, but this is
+% By default, the functions below return |0\exp_stop_f:|, but this is
% superseded by \cs{@@_round_return_one:}, which instead returns
-% \cs{c_one}, expanding everything and removing \cs{c_zero} in the
+% |1\exp_stop_f:|, expanding everything and removing |0\exp_stop_f:| in the
% process. In the case of rounding towards~$\pm\infty$ or
% towards~$0$, this is not really useful, but it prepares us for the
% \enquote{round to nearest, ties to even} mode.
@@ -155,29 +163,29 @@
% or up towards $+\infty$.
% \begin{macrocode}
\cs_new:Npn \@@_round_return_one:
- { \exp_after:wN \c_one \exp:w }
+ { \exp_after:wN 1 \exp_after:wN \exp_stop_f: \exp:w }
\cs_new:Npn \@@_round_to_ninf:NNN #1 #2 #3
{
\if_meaning:w 2 #1
- \if_int_compare:w #3 > \c_zero
+ \if_int_compare:w #3 > 0 \exp_stop_f:
\@@_round_return_one:
\fi:
\fi:
- \c_zero
+ 0 \exp_stop_f:
}
-\cs_new:Npn \@@_round_to_zero:NNN #1 #2 #3 { \c_zero }
+\cs_new:Npn \@@_round_to_zero:NNN #1 #2 #3 { 0 \exp_stop_f: }
\cs_new:Npn \@@_round_to_pinf:NNN #1 #2 #3
{
\if_meaning:w 0 #1
- \if_int_compare:w #3 > \c_zero
+ \if_int_compare:w #3 > 0 \exp_stop_f:
\@@_round_return_one:
\fi:
\fi:
- \c_zero
+ 0 \exp_stop_f:
}
\cs_new:Npn \@@_round_to_nearest:NNN #1 #2 #3
{
- \if_int_compare:w #3 > \c_five
+ \if_int_compare:w #3 > \c_@@_five_int
\@@_round_return_one:
\else:
\if_meaning:w 5 #3
@@ -186,11 +194,11 @@
\fi:
\fi:
\fi:
- \c_zero
+ 0 \exp_stop_f:
}
\cs_new:Npn \@@_round_to_nearest_ninf:NNN #1 #2 #3
{
- \if_int_compare:w #3 > \c_five
+ \if_int_compare:w #3 > \c_@@_five_int
\@@_round_return_one:
\else:
\if_meaning:w 5 #3
@@ -199,18 +207,18 @@
\fi:
\fi:
\fi:
- \c_zero
+ 0 \exp_stop_f:
}
\cs_new:Npn \@@_round_to_nearest_zero:NNN #1 #2 #3
{
- \if_int_compare:w #3 > \c_five
+ \if_int_compare:w #3 > \c_@@_five_int
\@@_round_return_one:
\fi:
- \c_zero
+ 0 \exp_stop_f:
}
\cs_new:Npn \@@_round_to_nearest_pinf:NNN #1 #2 #3
{
- \if_int_compare:w #3 > \c_five
+ \if_int_compare:w #3 > \c_@@_five_int
\@@_round_return_one:
\else:
\if_meaning:w 5 #3
@@ -219,7 +227,7 @@
\fi:
\fi:
\fi:
- \c_zero
+ 0 \exp_stop_f:
}
\cs_new_eq:NN \@@_round:NNN \@@_round_to_nearest:NNN
% \end{macrocode}
@@ -231,9 +239,9 @@
% \cs{@@_round_s:NNNw} \meta{final sign} \meta{digit} \meta{more digits} |;|
% \end{syntax}
% Similar to \cs{@@_round:NNN}, but with an extra semicolon, this
-% function expands to |\c_zero ;| if rounding $\meta{final sign}
+% function expands to |0\exp_stop_f:;| if rounding $\meta{final sign}
% \meta{digit}.\meta{more digits}$ to an integer truncates, and to
-% |\c_one ;| otherwise. The \meta{more digits} part must be a digit,
+% |1\exp_stop_f:;| otherwise. The \meta{more digits} part must be a digit,
% followed by something that does not overflow a \cs{int_use:N}
% \cs{__int_eval:w} construction. The only relevant information about
% this piece is whether it is zero or not.
@@ -247,7 +255,7 @@
\if_int_odd:w 0 \if_meaning:w 0 #3 1 \fi:
\if_meaning:w 5 #3 1 \fi:
\exp_stop_f:
- \if_int_compare:w \__int_eval:w #4 > \c_zero
+ \if_int_compare:w \__int_eval:w #4 > 0 \exp_stop_f:
1 +
\fi:
\fi:
@@ -269,11 +277,11 @@
% \begin{macrocode}
\cs_new:Npn \@@_round_digit:Nw #1 #2;
{
- \if_int_odd:w \if_meaning:w 0 #1 \c_one \else:
- \if_meaning:w 5 #1 \c_one \else:
- \c_zero \fi: \fi:
- \if_int_compare:w \__int_eval:w #2 > \c_zero
- \__int_eval:w \c_one +
+ \if_int_odd:w \if_meaning:w 0 #1 1 \else:
+ \if_meaning:w 5 #1 1 \else:
+ 0 \fi: \fi: \exp_stop_f:
+ \if_int_compare:w \__int_eval:w #2 > 0 \exp_stop_f:
+ \__int_eval:w 1 +
\fi:
\fi:
#1
@@ -295,15 +303,15 @@
% \begin{syntax}
% \cs{@@_round_neg:NNN} \meta{final sign} \meta{digit_1} \meta{digit_2}
% \end{syntax}
-% This expands to \cs{c_zero} or \cs{c_one} after doing the following
+% This expands to |0\exp_stop_f:| or |1\exp_stop_f:| after doing the following
% test. Starting from a number of
% the form $ \meta{final sign}0.\meta{15 digits}\meta{digit_1} $ with exactly
% $15$ (non-all-zero) digits before \meta{digit_1}, subtract from it
% $\meta{final sign}0.0\ldots{}0\meta{digit_2}$, where there are $16$~zeros.
% If in the current rounding mode the result should be rounded down,
-% then this function returns \cs{c_one}. Otherwise, \emph{i.e.},
+% then this function returns |1\exp_stop_f:|. Otherwise, \emph{i.e.},
% if the result is rounded back to the first operand, then this function
-% returns \cs{c_zero}.
+% returns |0\exp_stop_f:|.
%
% It turns out that this negative \enquote{round to nearest}
% is identical to the positive one. And this is the default mode.
@@ -311,20 +319,20 @@
\cs_new_eq:NN \@@_round_to_ninf_neg:NNN \@@_round_to_pinf:NNN
\cs_new:Npn \@@_round_to_zero_neg:NNN #1 #2 #3
{
- \if_int_compare:w #3 > \c_zero
+ \if_int_compare:w #3 > 0 \exp_stop_f:
\@@_round_return_one:
\fi:
- \c_zero
+ 0 \exp_stop_f:
}
\cs_new_eq:NN \@@_round_to_pinf_neg:NNN \@@_round_to_ninf:NNN
\cs_new_eq:NN \@@_round_to_nearest_neg:NNN \@@_round_to_nearest:NNN
\cs_new_eq:NN \@@_round_to_nearest_ninf_neg:NNN \@@_round_to_nearest_pinf:NNN
\cs_new:Npn \@@_round_to_nearest_zero_neg:NNN #1 #2 #3
{
- \if_int_compare:w #3 > \c_four
+ \if_int_compare:w #3 < \c_@@_five_int \else:
\@@_round_return_one:
\fi:
- \c_zero
+ 0 \exp_stop_f:
}
\cs_new_eq:NN \@@_round_to_nearest_pinf_neg:NNN \@@_round_to_nearest_ninf:NNN
\cs_new_eq:NN \@@_round_neg:NNN \@@_round_to_nearest_neg:NNN
@@ -459,19 +467,19 @@
}
\cs_new:Npn \@@_round_normal:NwNNnw #1#2 \s_@@ \@@_chk:w 1#3#4#5;
{
- \@@_decimate:nNnnnn { \c_sixteen - #4 - #2 }
+ \@@_decimate:nNnnnn { \c_@@_prec_int - #4 - #2 }
\@@_round_normal:NnnwNNnn #5 #1 #3 {#4} {#2}
}
\cs_new:Npn \@@_round_normal:NnnwNNnn #1#2#3#4; #5#6
{
\exp_after:wN \@@_round_normal:NNwNnn
\__int_value:w \__int_eval:w
- \if_int_compare:w #2 > \c_zero
+ \if_int_compare:w #2 > 0 \exp_stop_f:
1 \__int_value:w #2
\exp_after:wN \@@_round_pack:Nw
\__int_value:w \__int_eval:w 1#3 +
\else:
- \if_int_compare:w #3 > \c_zero
+ \if_int_compare:w #3 > 0 \exp_stop_f:
1 \__int_value:w #3 +
\fi:
\fi:
@@ -483,7 +491,7 @@
0000 0000 0000 0000 ; #6
}
\cs_new:Npn \@@_round_pack:Nw #1
- { \if_meaning:w 2 #1 + \c_one \fi: \__int_eval_end: }
+ { \if_meaning:w 2 #1 + 1 \fi: \__int_eval_end: }
\cs_new:Npn \@@_round_normal:NNwNnn #1 #2
{
\if_meaning:w 0 #2
@@ -508,7 +516,7 @@
\else:
\exp_after:wN \@@_round_special_aux:Nw
\exp_after:wN #4
- \__int_value:w \__int_eval:w \c_one
+ \__int_value:w \__int_eval:w 1
\if_meaning:w 1 #1 -#6 \else: +#5 \fi:
\fi:
;