diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3fp-basics.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3fp-basics.dtx | 115 |
1 files changed, 47 insertions, 68 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3fp-basics.dtx b/Master/texmf-dist/source/latex/l3kernel/l3fp-basics.dtx index 6b4ed3846d3..34e2124eb4a 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3fp-basics.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3fp-basics.dtx @@ -1,6 +1,6 @@ % \iffalse meta-comment % -%% File: l3fp-basics.dtx Copyright (C) 2011-2014,2016 The LaTeX3 Project +%% File: l3fp-basics.dtx Copyright (C) 2011-2014,2016,2017 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 @@ -22,8 +22,8 @@ % %<*driver> \documentclass[full]{l3doc} -\GetIdInfo$Id: l3fp-basics.dtx 6943 2017-02-17 16:47:59Z bruno $ - {L3 Floating-point arithmetic} +\def\ExplFileDate{2017/03/18} +\def\ExplFileVersion{7019} \begin{document} \DocInput{\jobname.dtx} \end{document} @@ -74,55 +74,20 @@ % Floating Point Arithmetic}, by David Goldberg, which can be found at % \texttt{http://cr.yp.to/2005-590/goldberg.pdf}. % -% \subsection{Common to several operations} -% % \begin{macro}[aux, EXP] % { -% \@@_basics_pack_low:NNNNNw, -% \@@_basics_pack_high:NNNNNw, -% \@@_basics_pack_high_carry:w +% \@@_parse_word_abs:N , +% \@@_parse_word_sign:N , +% \@@_parse_word_sqrt:N , % } -% Addition and multiplication of significands are done in two steps: -% first compute a (more or less) exact result, then round and pack -% digits in the final (braced) form. These functions take care of the -% packing, with special attention given to the case where rounding has -% caused a carry. Since rounding can only shift the final digit by -% $1$, a carry always produces an exact power of $10$. Thus, -% \cs{@@_basics_pack_high_carry:w} is always followed by four times -% |{0000}|. +% Unary functions. % \begin{macrocode} -\cs_new:Npn \@@_basics_pack_low:NNNNNw #1 #2#3#4#5 #6; - { + #1 - 1 ; {#2#3#4#5} {#6} ; } -\cs_new:Npn \@@_basics_pack_high:NNNNNw #1 #2#3#4#5 #6; - { - \if_meaning:w 2 #1 - \@@_basics_pack_high_carry:w - \fi: - ; {#2#3#4#5} {#6} - } -\cs_new:Npn \@@_basics_pack_high_carry:w \fi: ; #1 - { \fi: + 1 ; {1000} } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}[aux, EXP] -% { -% \@@_basics_pack_weird_low:NNNNw, -% \@@_basics_pack_weird_high:NNNNNNNNw -% } -% I don't fully understand those functions, used for additions and -% divisions. Hence the name. -% \begin{macrocode} -\cs_new:Npn \@@_basics_pack_weird_low:NNNNw #1 #2#3#4 #5; - { - \if_meaning:w 2 #1 - + 1 - \fi: - \__int_eval_end: - #2#3#4; {#5} ; - } -\cs_new:Npn \@@_basics_pack_weird_high:NNNNNNNNw - 1 #1#2#3#4 #5#6#7#8 #9; { ; {#1#2#3#4} {#5#6#7#8} {#9} } +\cs_new:Npn \@@_parse_word_abs:N + { \@@_parse_unary_function:NNN \@@_set_sign_o:w 0 } +\cs_new:Npn \@@_parse_word_sign:N + { \@@_parse_unary_function:NNN \@@_sign_o:w ? } +\cs_new:Npn \@@_parse_word_sqrt:N + { \@@_parse_unary_function:NNN \@@_sqrt_o:w ? } % \end{macrocode} % \end{macro} % @@ -149,7 +114,7 @@ % opposite signs, shift the significand of the smaller one to match the % bigger one, perform the addition or subtraction of significands, % check for a carry, round, and pack using the -% |\__fp_basics_pack_...| functions. +% \cs[no-index]{__fp_basics_pack_\ldots{}} functions. % \end{itemize} % The trickiest part is to round correctly when adding or subtracting % normal floating point numbers. @@ -157,15 +122,11 @@ % \subsubsection{Sign, exponent, and special numbers} % % \begin{macro}[int, EXP]{\@@_-_o:ww} -% A previous version of this function grabbed its two operands, -% changed the sign of the second, and called \cs{@@_+_o:ww}. However, -% for efficiency reasons, the operands were swapped in the process, -% which means that error messages ended up wrong. Now, the -% \cs{@@_+_o:ww} auxiliary has a hook: it takes one argument between -% the first \cs{s_@@} and \cs{@@_chk:w}, which is applied to the sign -% of the second operand. Positioning the hook there means that -% \cs{@@_+_o:ww} can still check that it was followed by \cs{s_@@} and -% not arbitrary junk. +% The \cs{@@_+_o:ww} auxiliary has a hook: it takes one argument +% between the first \cs{s_@@} and \cs{@@_chk:w}, which is applied to +% the sign of the second operand. Positioning the hook there means +% that \cs{@@_+_o:ww} can still perform the sanity check that it was +% followed by \cs{s_@@}. % \begin{macrocode} \cs_new:cpx { @@_-_o:ww } \s_@@ { @@ -178,8 +139,8 @@ % \begin{macro}[int, EXP]{\@@_+_o:ww} % This function is either called directly with an empty |#1| to % compute an addition, or it is called by \cs{@@_-_o:ww} with -% \cs{@@_neg_sign:N} as |#1| to compute a subtraction (equivalent to -% changing the \meta{sign_2} of the second operand). If the +% \cs{@@_neg_sign:N} as |#1| to compute a subtraction, in which case +% the second operand's sign should be changed. If the % \meta{types} |#2| and |#4| are the same, dispatch to case |#2| ($0$, % $1$, $2$, or $3$), where we call specialized functions: thanks to % \cs{__int_value:w}, those receive the tweaked \meta{sign_2} @@ -259,13 +220,8 @@ \else: \@@_case_use:nw { - \if_meaning:w #1 #4 - \exp_after:wN \@@_invalid_operation_o:Nww - \exp_after:wN + - \else: - \exp_after:wN \@@_invalid_operation_o:Nww - \exp_after:wN - - \fi: + \exp_last_unbraced:Nf \@@_invalid_operation_o:Nww + { \token_if_eq_meaning:NNTF #1 #4 + - } } \fi: \s_@@ \@@_chk:w 2 #2 #3; @@ -342,6 +298,7 @@ % \cs{@@_add_big_i_o:wNww} \meta{shift} |;| \meta{final sign} % \meta{body_1} |;| \meta{body_2} |;| % \end{quote} +% Used in \pkg{l3fp-expo}. % Shift the significand of the small number, then add with % \cs{@@_add_significand_o:NnnwnnnnN}. % \begin{macrocode} @@ -854,6 +811,8 @@ % significand. The \meta{final sign} is needed to do the rounding % properly in the significand computation. We setup the post-expansion % here, triggered by \cs{@@_mul_significand_o:nnnnNnnnn}. +% +% This is also used in \pkg{l3fp-convert}. % \begin{macrocode} \cs_new:Npn \@@_mul_npos_o:Nww #1 \s_@@ \@@_chk:w #2 #3 #4 #5 ; \s_@@ \@@_chk:w #6 #7 #8 #9 ; @@ -2070,7 +2029,27 @@ % \end{macrocode} % \end{macro} % -% \subsection{Setting the sign} +% \subsection{About the sign} +% +% \begin{macro}[int, EXP]{\@@_sign_o:w} +% \begin{macro}[aux, EXP]{\@@_sign_aux_o:w} +% Find the sign of the floating point: \texttt{nan}, |+0|, |-0|, |+1| or |-1|. +% \begin{macrocode} +\cs_new:Npn \@@_sign_o:w ? \s_@@ \@@_chk:w #1#2; @ + { + \if_case:w #1 \exp_stop_f: + \@@_case_return_same_o:w + \or: \exp_after:wN \@@_sign_aux_o:w + \or: \exp_after:wN \@@_sign_aux_o:w + \else: \@@_case_return_same_o:w + \fi: + \s_@@ \@@_chk:w #1 #2; + } +\cs_new:Npn \@@_sign_aux_o:w \s_@@ \@@_chk:w #1 #2 #3 ; + { \exp_after:wN \@@_set_sign_o:w \exp_after:wN #2 \c_one_fp @ } +% \end{macrocode} +% \end{macro} +% \end{macro} % % \begin{macro}[int, EXP]{\@@_set_sign_o:w} % This function is used for the unary minus and for \texttt{abs}. It |