summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3kernel/l3fp-aux.dtx
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-08-16 22:41:08 +0000
committerKarl Berry <karl@freefriends.org>2012-08-16 22:41:08 +0000
commitca1c73f9a8de69e467230c4a57ccf8b07cd275a9 (patch)
tree6272657307f73c14327d6b8bce5d6b7ff97c3f66 /Master/texmf-dist/source/latex/l3kernel/l3fp-aux.dtx
parent22c251adda514ed7b453066de05b2f89707d0fe6 (diff)
finish l3 update
git-svn-id: svn://tug.org/texlive/trunk@27427 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3fp-aux.dtx')
-rw-r--r--Master/texmf-dist/source/latex/l3kernel/l3fp-aux.dtx119
1 files changed, 94 insertions, 25 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3fp-aux.dtx b/Master/texmf-dist/source/latex/l3kernel/l3fp-aux.dtx
index 566eec13ec5..2a26c63ada5 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3fp-aux.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3fp-aux.dtx
@@ -35,8 +35,8 @@
%%
%
%<*driver>
-\RequirePackage{l3names}
-\GetIdInfo$Id: l3fp-aux.dtx 3986 2012-07-15 19:23:51Z joseph $
+\RequirePackage{l3bootstrap}
+\GetIdInfo$Id: l3fp-aux.dtx 4089 2012-08-14 04:52:20Z bruno $
{L3 Floating-point support functions}
\documentclass[full]{l3doc}
\begin{document}
@@ -80,6 +80,34 @@
%<@@=fp>
% \end{macrocode}
%
+% ^^A todo: make sanitize and pack more homogeneous between modules.
+%
+% ^^A begin[todo]: move
+% \section{Internal storage of floating points numbers}
+%
+% A floating point number \meta{X} is stored as
+% \begin{quote}
+% \cs{s_@@} \cs{@@_chk:w} \meta{case} \meta{sign} \meta{body} |;|
+% \end{quote}
+% Here, \meta{case} is 0 for $\pm 0$, 1 for normal numbers, 2 for $\pm
+% \infty$, and 3 for \texttt{nan}, and \meta{sign} is $0$ for positive
+% numbers, $1$ for \texttt{nan}s, and $2$ for negative numbers. The
+% \meta{body} of normal numbers is \Arg{exponent} \Arg{X_1} \Arg{X_2}
+% \Arg{X_3} \Arg{X_4}, with
+% \[
+% \meta{X} = (-1)^{\meta{sign}} 10^{-\meta{exponent}} \sum_i
+% \meta{X_i} 10^{-4i}.
+% \]
+% Calculations are done in base $10000$, \emph{i.e.} one myriad. The
+% \meta{exponent} lies between $\pm\cs{c_@@_max_exponent_int} = \pm
+% \the\csname\detokenize{c__fp_max_exponent_int}\endcsname$ inclusive.
+%
+% Additionally, positive and negative floating point numbers may only be
+% stored with $1000\leq\meta{X_1}<10000$. This requirement is necessary
+% in order to preserve accuracy and speed.
+%
+% ^^A end[todo]
+%
% \subsection{Using arguments and semicolons}
%
% \begin{macro}[int, EXP]{\@@_use_none_stop_f:n}
@@ -245,6 +273,16 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}[int, EXP]{\@@_neg_sign:N}
+% When appearing in an integer expression or after \cs{__int_value:w},
+% this expands to the sign opposite to |#1|, namely $0$ (positive) is
+% turned to $2$ (negative), $1$ (\texttt{nan}) to $1$, and $2$ to $0$.
+% \begin{macrocode}
+\cs_new:Npn \@@_neg_sign:N #1
+ { \__int_eval:w \c_two - #1 \__int_eval_end: }
+% \end{macrocode}
+% \end{macro}
+%
% \subsection{Overflow, underflow, and exact zero}
%
%^^A todo: the sign of exact zeros should depend on the rounding mode.
@@ -468,6 +506,27 @@
% \end{variable}
% \end{macro}
%
+% \begin{macro}[int, EXP]{\@@_pack_Bigg:NNNNNNw}
+% \begin{variable}
+% {
+% \c_@@_Bigg_trailing_shift_int ,
+% \c_@@_Bigg_middle_shift_int ,
+% \c_@@_Bigg_leading_shift_int ,
+% }
+% This set of shifts allows for computations involving results in the
+% range $[-1\cdot 10^{9}, 147483647]$; the end-point is $2^{31} - 1 -
+% 2\cdot 10^{9} \simeq 1.47\cdot 10^{8}$. Shifted values all have
+% exactly $10$ digits.
+% \begin{macrocode}
+\int_const:Nn \c_@@_Bigg_leading_shift_int { - 20 0000 }
+\int_const:Nn \c_@@_Bigg_middle_shift_int { 20 0000 * 9999 }
+\int_const:Nn \c_@@_Bigg_trailing_shift_int { 20 0000 * 10000 }
+\cs_new:Npn \@@_pack_Bigg:NNNNNNw #1#2 #3#4#5#6 #7;
+ { + #1#2#3#4#5#6 ; {#7} }
+% \end{macrocode}
+% \end{variable}
+% \end{macro}
+%
% \begin{macro}[int, EXP]{\@@_pack_twice_four:wNNNNNNNN}
% \begin{syntax}
% \cs{@@_pack_twice_four:wNNNNNNNN} \meta{tokens} |;| \meta{$\geq 8$ digits}
@@ -482,6 +541,20 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}[int, EXP]{\@@_pack_eight:wNNNNNNNN}
+% \begin{syntax}
+% \cs{@@_pack_eight:wNNNNNNNN} \meta{tokens} |;| \meta{$\geq 8$ digits}
+% \end{syntax}
+% Grabs one set of $8$ digits and places them before the semi-colon
+% delimiter as a single group. Putting several copies of this
+% function before a semicolon will pack more digits since each will
+% take the digits packed by the others in its first argument.
+% \begin{macrocode}
+\cs_new:Npn \@@_pack_eight:wNNNNNNNN #1; #2#3#4#5 #6#7#8#9
+ { #1 {#2#3#4#5#6#7#8#9} ; }
+% \end{macrocode}
+% \end{macro}
+%
% \subsection{Decimate (dividing by a power of 10)}
%
% ^^A begin[todo]
@@ -569,7 +642,7 @@
% The arguments are as follows: |#1| indicates which function is
% being defined; after one step of expansion, |#2| yields the
% \enquote{extra digits} which are then converted by
-% \cs{@@_decimate_round:Nw} to the \meta{rounding} digit.
+% \cs{@@_round_digit:Nw} to the \meta{rounding} digit.
% This triggers the \texttt{f}-expansion of
% \cs{@@_decimate_pack:nnnnnnnnnnw},\footnote{No, the argument
% spec is not a mistake: the function calls an auxiliary to
@@ -585,7 +658,7 @@
{
\exp_after:wN ##1
\__int_value:w
- \exp_after:wN \@@_decimate_round:Nw #2 ;
+ \exp_after:wN \@@_round_digit:Nw #2 ;
\@@_decimate_pack:nnnnnnnnnnw #3 ;
}
}
@@ -609,29 +682,19 @@
% \end{macro}
%
% \begin{macro}[EXP, aux]
-% {\@@_decimate_round:Nw, \@@_decimate_pack:nnnnnnnnnnw}
-% \cs{@@_decimate_round:Nw} will receive the \enquote{extra digits}
+% {\@@_round_digit:Nw, \@@_decimate_pack:nnnnnnnnnnw}
+% % ^^A \cs{@@_round_digit:Nw} moved to \pkg{l3fp-round}.
+% \cs{@@_round_digit:Nw} will receive the \enquote{extra digits}
% as its argument, and its expansion is triggered by \cs{__int_value:w}.
% If the first digit is neither $0$ nor $5$, then it is the \meta{rounding}
% digit. Otherwise, if the remaining digits are not all zero, we need
% to add $1$ to that leading digit to get the rounding digit. Some caution
% is required, though, because there may be more than $10$
% \enquote{extra digits}, and this may overflow \TeX{}'s integers.
-% Instead of feeding the digits directly to \cs{@@_decimate_round:Nw},
+% Instead of feeding the digits directly to \cs{@@_round_digit:Nw},
% they come split into several blocks, separated by $+$. Hence the first
% \cs{__int_eval:w} here.
% \begin{macrocode}
-\cs_new:Npn \@@_decimate_round: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 1 +
- \fi:
- \fi:
- #1
- }
% \end{macrocode}
% The computation of the \meta{rounding} digit leaves an unfinished
% \cs{__int_value:w}, which expands the following functions. This
@@ -706,7 +769,7 @@
%
% \begin{macro}[int, EXP]{\@@_case_return_o:Nw}
% This function ends a \TeX{} conditional, removes junk and a floating
-% point, and returns its first argument, a \meta{fp~var}, expanding
+% point, and returns its first argument (an \meta{fp~var}) then expands
% once after it.
% \begin{macrocode}
\cs_new:Npn \@@_case_return_o:Nw #1#2 \fi: #3 \s_@@ #4 ;
@@ -732,10 +795,13 @@
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}[int, EXP]{\@@_case_return_ii_o:ww}
-% Similar to \cs{@@_case_return_same_o:w}, but this returns the second
-% of two trailing floating point numbers, expanding once after it.
+% \begin{macro}[int, EXP]{\@@_case_return_i_o:ww, \@@_case_return_ii_o:ww}
+% Similar to \cs{@@_case_return_same_o:w}, but this returns the first
+% or second of two trailing floating point numbers, expanding once
+% after the result.
% \begin{macrocode}
+\cs_new:Npn \@@_case_return_i_o:ww #1 \fi: #2 \s_@@ #3 ; \s_@@ #4 ;
+ { \fi: \@@_exp_after_o:w \s_@@ #3 ; }
\cs_new:Npn \@@_case_return_ii_o:ww #1 \fi: #2 \s_@@ #3 ;
{ \fi: \@@_exp_after_o:w }
% \end{macrocode}
@@ -763,7 +829,10 @@
% appearing in the case where the normal floating point is an integer
% takes care of expanding all the conditionals until the trailing |;|.
% That integer is fed to \cs{@@_small_int_true:wTF} which places it as
-% a braced argument of the true branch.
+% a braced argument of the true branch. The \cs{use_i:nn} in
+% \cs{@@_small_int_test:NnnwNTF} removes the top-level \cs{else:}
+% coming from \cs{@@_small_int_normal:NnwTF}, hence will call the
+% \cs{use_iii:nnn} which follows, taking the false branch.
% \begin{macrocode}
\cs_new:Npn \@@_small_int:wTF \s_@@ \@@_chk:w #1
{
@@ -796,7 +865,7 @@
\exp_after:wN \@@_small_int_true:wTF
\__int_value:w \if_meaning:w 2 #5 - \fi: #3
\else:
- \exp_after:wN \use_iii:nnn
+ \exp_after:wN \use_i:nn
\fi:
}
% \end{macrocode}
@@ -847,4 +916,4 @@
%
% \PrintChanges
%
-% \PrintIndex \ No newline at end of file
+% \PrintIndex