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.dtx129
1 files changed, 101 insertions, 28 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx b/Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx
index a277f1b8952..844e229fa1a 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3fp-round.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-%% File: l3fp-round.dtx Copyright(C) 2011-2012,2014 The LaTeX3 Project
+%% File: l3fp-round.dtx Copyright(C) 2011-2012,2014,2015 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
@@ -36,7 +36,7 @@
%
%<*driver>
\documentclass[full]{l3doc}
-\GetIdInfo$Id: l3fp-round.dtx 5354 2014-08-23 01:35:39Z bruno $
+\GetIdInfo$Id: l3fp-round.dtx 5893 2015-08-26 16:16:52Z mittelba $
{L3 Floating-point rounding}
\begin{document}
\DocInput{\jobname.dtx}
@@ -129,6 +129,9 @@
% \begin{macro}[aux, rEXP]
% {
% \@@_round_to_nearest:NNN,
+% \@@_round_to_nearest_ninf:NNN,
+% \@@_round_to_nearest_zero:NNN,
+% \@@_round_to_nearest_pinf:NNN,
% \@@_round_to_ninf:NNN,
% \@@_round_to_zero:NNN,
% \@@_round_to_pinf:NNN
@@ -160,9 +163,13 @@
% than~$5$, round down. If it is exactly $5$, then round such that
% \meta{digit_1} plus the result is even. In other words, round up if
% \meta{digit_1} is odd.
+%
+% The \enquote{round to nearest} mode has three variants, which differ
+% in how ties are rounded: down towards $-\infty$, truncated towards $0$,
+% or up towards $+\infty$.
% \begin{macrocode}
\cs_new:Npn \@@_round_return_one:
- { \exp_after:wN \c_one \tex_romannumeral:D }
+ { \exp_after:wN \c_one \exp:w }
\cs_new:Npn \@@_round_to_ninf:NNN #1 #2 #3
{
\if_meaning:w 2 #1
@@ -195,6 +202,39 @@
\fi:
\c_zero
}
+\cs_new:Npn \@@_round_to_nearest_ninf:NNN #1 #2 #3
+ {
+ \if_int_compare:w #3 > \c_five
+ \@@_round_return_one:
+ \else:
+ \if_meaning:w 5 #3
+ \if_meaning:w 2 #1
+ \@@_round_return_one:
+ \fi:
+ \fi:
+ \fi:
+ \c_zero
+ }
+\cs_new:Npn \@@_round_to_nearest_zero:NNN #1 #2 #3
+ {
+ \if_int_compare:w #3 > \c_five
+ \@@_round_return_one:
+ \fi:
+ \c_zero
+ }
+\cs_new:Npn \@@_round_to_nearest_pinf:NNN #1 #2 #3
+ {
+ \if_int_compare:w #3 > \c_five
+ \@@_round_return_one:
+ \else:
+ \if_meaning:w 5 #3
+ \if_meaning:w 0 #1
+ \@@_round_return_one:
+ \fi:
+ \fi:
+ \fi:
+ \c_zero
+ }
\cs_new_eq:NN \@@_round:NNN \@@_round_to_nearest:NNN
% \end{macrocode}
% \end{macro}
@@ -259,6 +299,9 @@
% \begin{macro}[aux, EXP]
% {
% \@@_round_to_nearest_neg:NNN,
+% \@@_round_to_nearest_ninf_neg:NNN,
+% \@@_round_to_nearest_zero_neg:NNN,
+% \@@_round_to_nearest_pinf_neg:NNN,
% \@@_round_to_ninf_neg:NNN,
% \@@_round_to_zero_neg:NNN,
% \@@_round_to_pinf_neg:NNN
@@ -279,15 +322,7 @@
% It turns out that this negative \enquote{round to nearest}
% is identical to the positive one. And this is the default mode.
% \begin{macrocode}
-\cs_new:Npn \@@_round_to_ninf_neg:NNN #1 #2 #3
- {
- \if_meaning:w 0 #1
- \if_int_compare:w #3 > \c_zero
- \@@_round_return_one:
- \fi:
- \fi:
- \c_zero
- }
+\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
@@ -295,16 +330,17 @@
\fi:
\c_zero
}
-\cs_new:Npn \@@_round_to_pinf_neg:NNN #1 #2 #3
+\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_meaning:w 2 #1
- \if_int_compare:w #3 > \c_zero
- \@@_round_return_one:
- \fi:
+ \if_int_compare:w #3 > \c_four
+ \@@_round_return_one:
\fi:
\c_zero
}
-\cs_new_eq:NN \@@_round_to_nearest_neg:NNN \@@_round_to_nearest:NNN
+\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
% \end{macrocode}
% \end{macro}
@@ -315,20 +351,57 @@
% ^^A todo: This macro is intermingled with l3fp-parse.
% ^^A todo: Add explanations.
% \begin{macro}[aux,EXP]{\@@_round_o:Nw}
-% This function expects one or two arguments.
+% The |trunc|, |ceil| and |floor| functions expect one or two
+% arguments (the second is $0$ by default), and the |round| function
+% also accepts a third argument (\texttt{nan} by default), which
+% will change |#1| from \cs{@@_round_to_nearest:NNN} to one of its
+% analogues.
% \begin{macrocode}
\cs_new:Npn \@@_round_o:Nw #1#2 @
{
\if_case:w
\__int_eval:w \@@_array_count:n {#2} - \c_one \__int_eval_end:
- \@@_round:Nwn #1 #2 {0} \tex_romannumeral:D
- \or: \@@_round:Nww #1 #2 \tex_romannumeral:D
- \else:
- \@@_error:nffn { num-args }
- { \@@_round_name_from_cs:N #1 () } { 1 } { 2 }
- \exp_after:wN \c_nan_fp \tex_romannumeral:D
+ \@@_round:Nwn #1 #2 {0} \exp:w
+ \or: \@@_round:Nww #1 #2 \exp:w
+ \else: \@@_round:Nwww #1 #2 @ \exp:w
\fi:
- -`0
+ \exp_end_continue_f:w
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[aux, EXP]{\@@_round:Nwww}
+% Having three arguments is only allowed for |round|, not |trunc|,
+% |ceil|, |floor|, so check for that case. If all is well, construct
+% one of \cs{@@_round_to_nearest:NNN}, \cs{@@_round_to_nearest_zero:NNN},
+% \cs{@@_round_to_nearest_ninf:NNN}, \cs{@@_round_to_nearest_pinf:NNN}
+% and act accordingly.
+% \begin{macrocode}
+\cs_new:Npn \@@_round:Nwww #1#2 ; #3 ; \s_@@ \@@_chk:w #4#5#6 ; #7 @
+ {
+ \cs_if_eq:NNTF #1 \@@_round_to_nearest:NNN
+ {
+ \tl_if_empty:nTF {#7}
+ {
+ \exp_args:Nc \@@_round:Nww
+ {
+ @@_round_to_nearest
+ \if_meaning:w 0 #4 _zero \else:
+ \if_case:w #5 \exp_stop_f: _pinf \or: \else: _ninf \fi: \fi:
+ :NNN
+ }
+ #2 ; #3 ;
+ }
+ {
+ \@@_error:nnnn { num-args } { round () } { 1 } { 3 }
+ \exp_after:wN \c_nan_fp
+ }
+ }
+ {
+ \@@_error:nffn { num-args }
+ { \@@_round_name_from_cs:N #1 () } { 1 } { 2 }
+ \exp_after:wN \c_nan_fp
+ }
}
% \end{macrocode}
% \end{macro}
@@ -421,7 +494,7 @@
}
\cs_new:Npn \@@_round_normal_end:wwNnn #1;#2;#3#4#5
{
- \exp_after:wN \@@_exp_after_o:w \tex_romannumeral:D -`0
+ \exp_after:wN \@@_exp_after_o:w \exp:w \exp_end_continue_f:w
\@@_sanitize:Nw #3 #4 ; #1 ;
}
\cs_new:Npn \@@_round_special:NwwNnn #1#2;#3;#4#5#6
@@ -439,7 +512,7 @@
}
\cs_new:Npn \@@_round_special_aux:Nw #1#2;
{
- \exp_after:wN \@@_exp_after_o:w \tex_romannumeral:D -`0
+ \exp_after:wN \@@_exp_after_o:w \exp:w \exp_end_continue_f:w
\@@_sanitize:Nw #1#2; {1000}{0000}{0000}{0000};
}
% \end{macrocode}