From a3486a2d404fca82e9fc0db0a72c7d61efe4824b Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 19 Dec 2010 00:30:41 +0000 Subject: expl3 2103 (18dec10) git-svn-id: svn://tug.org/texlive/trunk@20793 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/expl3/expl3.pdf | Bin 512728 -> 512728 bytes Master/texmf-dist/doc/latex/expl3/l3calc.pdf | Bin 377232 -> 377232 bytes Master/texmf-dist/doc/latex/expl3/source3.pdf | Bin 1525597 -> 1566978 bytes Master/texmf-dist/source/latex/expl3/l3fp.dtx | 2262 ++++++++++++++++++++++--- Master/texmf-dist/source/latex/expl3/l3tl.dtx | 4 +- Master/texmf-dist/tex/latex/expl3/l3fp.sty | 1485 ++++++++++++++-- Master/texmf-dist/tex/latex/expl3/l3tl.sty | 4 +- 7 files changed, 3310 insertions(+), 445 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/expl3/expl3.pdf b/Master/texmf-dist/doc/latex/expl3/expl3.pdf index 495ba14c90b..4d7031157c1 100644 Binary files a/Master/texmf-dist/doc/latex/expl3/expl3.pdf and b/Master/texmf-dist/doc/latex/expl3/expl3.pdf differ diff --git a/Master/texmf-dist/doc/latex/expl3/l3calc.pdf b/Master/texmf-dist/doc/latex/expl3/l3calc.pdf index b7f84e689ea..72c3a8a8c21 100644 Binary files a/Master/texmf-dist/doc/latex/expl3/l3calc.pdf and b/Master/texmf-dist/doc/latex/expl3/l3calc.pdf differ diff --git a/Master/texmf-dist/doc/latex/expl3/source3.pdf b/Master/texmf-dist/doc/latex/expl3/source3.pdf index 274b62d1bfc..7d0fc94fb96 100644 Binary files a/Master/texmf-dist/doc/latex/expl3/source3.pdf and b/Master/texmf-dist/doc/latex/expl3/source3.pdf differ diff --git a/Master/texmf-dist/source/latex/expl3/l3fp.dtx b/Master/texmf-dist/source/latex/expl3/l3fp.dtx index f5b1d427096..8eb2530143c 100644 --- a/Master/texmf-dist/source/latex/expl3/l3fp.dtx +++ b/Master/texmf-dist/source/latex/expl3/l3fp.dtx @@ -35,7 +35,7 @@ \RequirePackage{l3names} % %\fi -\GetIdInfo$Id: l3fp.dtx 2092 2010-11-25 20:44:04Z joseph $ +\GetIdInfo$Id: l3fp.dtx 2104 2010-12-18 09:29:34Z joseph $ {L3 Experimental floating-point operations} %\iffalse %<*driver> @@ -65,8 +65,8 @@ % A floating point number is one which is stored as a mantissa and % a separate exponent. This module implements arithmetic using radix % \( 10 \) floating point numbers. This means that the mantissa should -% be a real number in the range \( 1 \le \string| x \string| < 10 \), -% with the +% be a real number in the range \( 1 \le \expandafter\mathopen\string| +% x \expandafter\mathclose\string| < 10 \), with the % exponent given as an integer between \( -99 \) and \( 99 \). In the % input, the exponent part is represented starting with an \texttt{e}. % As this is a low-level module, error-checking is minimal. Numbers @@ -100,11 +100,19 @@ % %\subsection{Constants} % +%\begin{variable}{ \c_e_fp } +% The value of the base of natural numbers, \( \mathrm{e} \). +%\end{variable} +% %\begin{variable}{ \c_one_fp } % A floating point variable with permanent value \( 1 \): used for % speeding up some comparisons. %\end{variable} % +%\begin{variable}{ \c_pi_fp } +% The value of \( \pi \). +%\end{variable} +% %\begin{variable}{ \c_undefined_fp } % A special marker floating point variable representing the result of % an operation which does not give a defined result (such as division @@ -131,6 +139,19 @@ %\end{function} % %\begin{function}{ +% \fp_const:Nn | +% \fp_const:cn | +%} +% \begin{syntax} +% \cs{fp_const:Nn} \meta{floating point variable} \Arg{value} +% \end{syntax} +% Creates a new constant \meta{floating point variable} or raises an +% error if the name is already taken. The value of the +% \meta{floating point variable} will be set globally to the +% \meta{value}. +%\end{function} +% +%\begin{function}{ % \fp_set_eq:NN | % \fp_set_eq:cN | % \fp_set_eq:Nc | @@ -413,22 +434,25 @@ % input stream by the predicate version. %\end{function} % -%\begin{function}{ -% \fp_compare:nNn / (TF) | -% \fp_compare:NNN / (TF) | -%} +%\begin{function}{ \fp_compare:nNn / (TF) } % \begin{syntax} -% \cs{fp_compare:nNnTF} \Arg{value1} \meta{relation} \Arg{value2} -% ~~\Arg{true code} \Arg{false code} -% \cs{fp_compare:NNNTF} \Arg{fp1} \meta{relation} \Arg{fp2} +% \cs{fp_compare:nNnTF} +% ~~\Arg{floating point1} \meta{relation} \Arg{floating point2} % ~~\Arg{true code} \Arg{false code} % \end{syntax} -% Compares the two \meta{values} or \meta{floating points} based on the -% \meta{relation} (\texttt{=}, \verb"<" or \verb">"), and leaves -% either the \meta{true code} or \meta{false code} in the input stream, -% as appropriate to the truth of the test and the variant of the -% function chosen. The tests treat undefined floating points as zero, -% as the comparison is intended for real numbers only. +% This function compared the two \meta{floating point} values, which +% may be stored as \texttt{fp} variables, using the \meta{relation}: +% \begin{center} +% \begin{tabular}{ll} +% Equal & "=" \\ +% Greater than & ">" \\ +% Less than & "<" \\ +% \end{tabular} +% \end{center} +% Either \meta{true code} or \meta{false code} is then left in the +% input stream, as appropriate to the truth of the test and the variant +% of the function chosen. The tests treat undefined floating points as +% zero as the comparison is intended for real numbers only. %\end{function} % %\subsection{Unary operations} @@ -567,7 +591,7 @@ % Divides the \meta{floating point} by the \meta{value}, making the % assignment within the current \TeX\ group level. If the \meta{value} % is zero, the \meta{floating point} will be set to -% \cs{c_undefined_fp}. +% \cs{c_undefined_fp}.The assignment is local. %\end{function} % %\begin{function}{ @@ -580,12 +604,89 @@ % Divides the \meta{floating point} by the \meta{value}, making the % assignment globally. If the \meta{value} is zero, the % \meta{floating point} will be set to \cs{c_undefined_fp}. +% The assignment is global. +%\end{function} +% +%\subsection{Power operations} +% +%\begin{function}{ +% \fp_pow:Nn | +% \fp_pow:cn | +%} +% \begin{syntax} +% \cs{fp_pow:Nn} \meta{floating point} \Arg{value} +% \end{syntax} +% Raises the \meta{floating point} to the given \meta{value}, which +% should be a positive real number or a negative integer. +% Mathematically invalid operations such as \( 0^{0} \) will give +% set the \meta{floating point} to to \cs{c_undefined_fp}. The +% assignment is local. +%\end{function} +% +%\begin{function}{ +% \fp_gpow:Nn | +% \fp_gpow:cn | +%} +% \begin{syntax} +% \cs{fp_gpow:Nn} \meta{floating point} \Arg{value} +% \end{syntax} +% Raises the \meta{floating point} to the given \meta{value}, which +% should be a positive real number or a negative integer. +% Mathematically invalid operations such as \( 0^{0} \) will give +% set the \meta{floating point} to to \cs{c_undefined_fp}. The +% assignment is global. +%\end{function} +% +%\subsection{Exponential and logarithm functions} +% +%\begin{function}{ +% \fp_exp:Nn | +% \fp_exp:cn | +%} +% \begin{syntax} +% \cs{fp_exp:Nn} \meta{floating point} \Arg{value} +% \end{syntax} +% Calculates the exponential of the \meta{value} and assigns this +% to the \meta{floating point}. The assignment is local. +%\end{function} +% +%\begin{function}{ +% \fp_gexp:Nn | +% \fp_gexp:cn | +%} +% \begin{syntax} +% \cs{fp_gexp:Nn} \meta{floating point} \Arg{value} +% \end{syntax} +% Calculates the exponential of the \meta{value} and assigns this +% to the \meta{floating point}. The assignment is global. +%\end{function} +% +%\begin{function}{ +% \fp_ln:Nn | +% \fp_ln:cn | +%} +% \begin{syntax} +% \cs{fp_ln:Nn} \meta{floating point} \Arg{value} +% \end{syntax} +% Calculates the natural logarithm of the \meta{value} and assigns +% this to the \meta{floating point}. The assignment is local. +%\end{function} +% +%\begin{function}{ +% \fp_gln:Nn | +% \fp_gln:cn | +%} +% \begin{syntax} +% \cs{fp_gln:Nn} \meta{floating point} \Arg{value} +% \end{syntax} +% Calculates the natural logarithm of the \meta{value} and assigns +% this to the \meta{floating point}. The assignment is global. %\end{function} % %\subsection{Trigonometric functions} % % The trigonometric functions all work in radians. They accept a maximum -% input value of \( 1 000 000 000\), as there are issues with range +% input value of \( 100\,000\,000 \), as there are issues with range % reduction and very large input values. % %\begin{function}{ @@ -662,6 +763,14 @@ % %\subsection{Notes on the floating point unit} % +% As calculation of the elemental transcendental functions is +% computationally expensive compared to storage of results, after +% calculating a trigonometric function, exponent, \emph{etc}.~the module +% stored the result for reuse. Thus the performance of the module for +% repeated operations, most probably trigonometric functions, should be +% much higher than if the values were re-calculated every time they +% were needed. +% % Anyone with experience of programming floating point calculations will % know that this is a complex area. The aim of the unit is to be % accurate enough for the likely applications in a typesetting context. @@ -709,20 +818,13 @@ %\begin{macro}{\c_one_thousand_million} % There is some speed to gain by moving numbers into fixed positions. % \begin{macrocode} -\int_new:N \c_forty_four -\int_set:Nn \c_forty_four { 44 } -\int_new:N \c_one_hundred -\int_set:Nn \c_one_hundred { 100 } -\int_new:N \c_one_thousand -\int_set:Nn \c_one_thousand { 1000 } -\int_new:N \c_one_million -\int_set:Nn \c_one_million { 1 000 000 } -\int_new:N \c_one_hundred_million -\int_set:Nn \c_one_hundred_million { 100 000 000 } -\int_new:N \c_five_hundred_million -\int_set:Nn \c_five_hundred_million { 500 000 000 } -\int_new:N \c_one_thousand_million -\int_set:Nn \c_one_thousand_million { 1 000 000 000 } +\int_const:Nn \c_forty_four { 44 } +\int_const:Nn \c_one_hundred { 100 } +\int_const:Nn \c_one_thousand { 1000 } +\int_const:Nn \c_one_million { 1 000 000 } +\int_const:Nn \c_one_hundred_million { 100 000 000 } +\int_const:Nn \c_five_hundred_million { 500 000 000 } +\int_const:Nn \c_one_thousand_million { 1 000 000 000 } % \end{macrocode} %\end{macro} %\end{macro} @@ -738,7 +840,8 @@ %\begin{macro}{\c_fp_pi_extended_int} %\begin{macro}{\c_fp_two_pi_decimal_int} %\begin{macro}{\c_fp_two_pi_extended_int} -% Parts of \( \pi \) for trigonometric range reduction. +% Parts of \( \pi \) for trigonometric range reduction, implemented +% as \texttt{int} variables for speed. % \begin{macrocode} \int_new:N \c_fp_pi_by_four_decimal_int \int_set:Nn \c_fp_pi_by_four_decimal_int { 785 398 158 } @@ -760,18 +863,26 @@ %\end{macro} %\end{macro} % +%\begin{macro}{\c_e_fp} +% The value \( \mathrm{e} \) as a `machine number'. +% \begin{macrocode} +\tl_new:N \c_e_fp +\tl_set:Nn \c_e_fp { + 2.718281828 e 0 } +% \end{macrocode} +%\end{macro} +% %\begin{macro}{\c_one_fp} % The constant value \( 1 \): used for fast comparisons. % \begin{macrocode} -\tl_new:N \c_one_fp +\tl_new:N \c_one_fp \tl_set:Nn \c_one_fp { + 1.000000000 e 0 } % \end{macrocode} %\end{macro} % %\begin{macro}{\c_pi_fp} -% The value \( \pi \), as a `machine number'. +% The value \( \pi \) as a `machine number'. % \begin{macrocode} -\tl_new:N \c_pi_fp +\tl_new:N \c_pi_fp \tl_set:Nn \c_pi_fp { + 3.141592654 e 0 } % \end{macrocode} %\end{macro} @@ -779,7 +890,7 @@ %\begin{macro}{\c_undefined_fp} % A marker for undefined values. % \begin{macrocode} -\tl_new:N \c_undefined_fp +\tl_new:N \c_undefined_fp \tl_set:Nn \c_undefined_fp { X 0.000000000 e 0 } % \end{macrocode} %\end{macro} @@ -787,13 +898,21 @@ %\begin{macro}{\c_zero_fp} % The constant zero value. % \begin{macrocode} -\tl_new:N \c_zero_fp +\tl_new:N \c_zero_fp \tl_set:Nn \c_zero_fp { + 0.000000000 e 0 } % \end{macrocode} %\end{macro} % %\subsection{Variables} % +%\begin{macro}{\l_fp_arg_tl} +% A token list to store the formalised representation of the input +% for transcendental functions. +% \begin{macrocode} +\tl_new:N \l_fp_arg_tl +% \end{macrocode} +%\end{macro} +% %\begin{macro}{\l_fp_count_int} % A counter for things like the number of divisions possible. % \begin{macrocode} @@ -809,6 +928,22 @@ % \end{macrocode} %\end{macro} % +%\begin{macro}{\l_fp_exp_integer_int} +%\begin{macro}{\l_fp_exp_decimal_int} +%\begin{macro}{\l_fp_exp_extended_int} +%\begin{macro}{\l_fp_exp_exponent_int} +% Used for the calculation of exponent values. +% \begin{macrocode} +\int_new:N \l_fp_exp_integer_int +\int_new:N \l_fp_exp_decimal_int +\int_new:N \l_fp_exp_extended_int +\int_new:N \l_fp_exp_exponent_int +% \end{macrocode} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +% %\begin{macro}{\l_fp_input_a_sign_int} %\begin{macro}{\l_fp_input_a_integer_int} %\begin{macro}{\l_fp_input_a_decimal_int} @@ -948,6 +1083,14 @@ %\end{macro} %\end{macro} % +%\begin{macro}{\l_fp_sign_tl} +% There are places where the sign needs to be set up `early', +% so that the registers can be re-used. +% \begin{macrocode} +\tl_new:N \l_fp_sign_tl +% \end{macrocode} +%\end{macro} +% %\begin{macro}{\l_fp_split_sign_int} % When splitting the input it is fastest to use a fixed name for the % sign part, and to transfer it after the split is complete. @@ -971,14 +1114,6 @@ % \end{macrocode} %\end{macro} % -%\begin{macro}{\l_fp_trig_arg_tl} -% A token list to store the formalised representation of the input -% for trigonometry. -% \begin{macrocode} -\tl_new:N \l_fp_trig_arg_tl -% \end{macrocode} -%\end{macro} -% %\begin{macro}{\l_fp_trig_octant_int} % To track which octant the trigonometric input is in. % \begin{macrocode} @@ -1008,7 +1143,7 @@ % value (register "a"). % \begin{macrocode} \cs_new_protected_nopar:Npn \fp_read:N #1 { - \exp_after:wN \fp_read_aux:w #1 \q_stop + \tex_expandafter:D \fp_read_aux:w #1 \q_stop } \cs_new_protected_nopar:Npn \fp_read_aux:w #1#2 . #3 e #4 \q_stop { \tex_if:D #1 - @@ -1049,29 +1184,29 @@ \l_fp_split_sign_int \c_one \fp_split_sign: \use:c { l_fp_input_ #1 _sign_int } \l_fp_split_sign_int - \exp_after:wN \fp_split_exponent:w \l_fp_tmp_tl e e \q_stop #1 + \tex_expandafter:D \fp_split_exponent:w \l_fp_tmp_tl e e \q_stop #1 } \cs_new_protected_nopar:Npn \fp_split_sign: { \tex_ifnum:D \pdf_strcmp:D - { \exp_after:wN \tl_head:w \l_fp_tmp_tl ? \q_stop } { - } + { \tex_expandafter:D \tl_head:w \l_fp_tmp_tl ? \q_stop } { - } = \c_zero \tl_set:Nx \l_fp_tmp_tl { - \exp_after:wN + \tex_expandafter:D \tl_tail:w \l_fp_tmp_tl \prg_do_nothing: \q_stop } \l_fp_split_sign_int -\l_fp_split_sign_int - \exp_after:wN \fp_split_sign: + \tex_expandafter:D \fp_split_sign: \tex_else:D \tex_ifnum:D \pdf_strcmp:D - { \exp_after:wN \tl_head:w \l_fp_tmp_tl ? \q_stop } { + } + { \tex_expandafter:D \tl_head:w \l_fp_tmp_tl ? \q_stop } { + } = \c_zero \tl_set:Nx \l_fp_tmp_tl { - \exp_after:wN + \tex_expandafter:D \tl_tail:w \l_fp_tmp_tl \prg_do_nothing: \q_stop } - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_split_sign: \tex_fi:D \tex_fi:D @@ -1092,7 +1227,7 @@ } \cs_new_protected_nopar:Npn \fp_split_aux_iii:w #1#2 \q_stop { \l_fp_tmp_int 1 #1 \scan_stop: - \exp_after:wN \fp_split_decimal:w + \tex_expandafter:D \fp_split_decimal:w \int_use:N \l_fp_tmp_int 000000000 \q_stop } \cs_new_protected_nopar:Npn \fp_split_decimal:w #1#2#3#4#5#6#7#8#9 { @@ -1111,7 +1246,7 @@ \tex_ifnum:D \use:c { l_fp_input_ #4 _integer_int } < \c_one_thousand_million \tex_else:D - \exp_after:wN \fp_overflow_msg: + \tex_expandafter:D \fp_overflow_msg: \tex_fi:D } % \end{macrocode} @@ -1137,9 +1272,9 @@ \etex_numexpr:D #2 + #3 = \c_zero #1 \c_one #4 \c_zero - \exp_after:wN \use_none:nnnn + \tex_expandafter:D \use_none:nnnn \tex_else:D - \exp_after:wN \fp_standardise_aux:NNNN + \tex_expandafter:D \fp_standardise_aux:NNNN \tex_fi:D #1#2#3#4 } @@ -1148,9 +1283,9 @@ { \tex_ifnum:D #2 = \c_zero \tex_advance:D #3 \c_one_thousand_million - \exp_after:wN \fp_standardise_aux:w + \tex_expandafter:D \fp_standardise_aux:w \int_use:N #3 \q_stop - \exp_after:wN \fp_standardise_aux: + \tex_expandafter:D \fp_standardise_aux: \tex_fi:D } \cs_set_protected_nopar:Npn @@ -1165,9 +1300,9 @@ { \tex_ifnum:D #2 > \c_nine \tex_advance:D #2 \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_standardise_aux:w \int_use:N #2 - \exp_after:wN \fp_standardise_aux: + \tex_expandafter:D \fp_standardise_aux: \tex_fi:D } \cs_set_protected_nopar:Npn @@ -1179,7 +1314,7 @@ \tl_set:Nx \l_fp_tmp_tl { ##9 - \exp_after:wN \use_none:n \int_use:N #3 + \tex_expandafter:D \use_none:n \int_use:N #3 } #3 \l_fp_tmp_tl \scan_stop: \tex_advance:D #4 \c_one @@ -1194,7 +1329,7 @@ #4 \c_zero \tex_fi:D \tex_else:D - \exp_after:wN \fp_overflow_msg: + \tex_expandafter:D \fp_overflow_msg: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_standardise_aux: { } @@ -1218,18 +1353,18 @@ % \begin{macrocode} \cs_new_protected_nopar:Npn \fp_level_input_exponents: { \tex_ifnum:D \l_fp_input_a_exponent_int > \l_fp_input_b_exponent_int - \exp_after:wN \fp_level_input_exponents_a: + \tex_expandafter:D \fp_level_input_exponents_a: \tex_else:D - \exp_after:wN \fp_level_input_exponents_b: + \tex_expandafter:D \fp_level_input_exponents_b: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_level_input_exponents_a: { \tex_ifnum:D \l_fp_input_a_exponent_int > \l_fp_input_b_exponent_int \tex_advance:D \l_fp_input_b_integer_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_level_input_exponents_a:NNNNNNNNN \int_use:N \l_fp_input_b_integer_int - \exp_after:wN \fp_level_input_exponents_a: + \tex_expandafter:D \fp_level_input_exponents_a: \tex_fi:D } \cs_new_protected_nopar:Npn @@ -1240,7 +1375,7 @@ \tl_set:Nx \l_fp_tmp_tl { #9 - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_b_decimal_int } \l_fp_input_b_decimal_int \l_fp_tmp_tl \scan_stop: @@ -1249,10 +1384,10 @@ \cs_new_protected_nopar:Npn \fp_level_input_exponents_b: { \tex_ifnum:D \l_fp_input_b_exponent_int > \l_fp_input_a_exponent_int \tex_advance:D \l_fp_input_a_integer_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_level_input_exponents_b:NNNNNNNNN \int_use:N \l_fp_input_a_integer_int - \exp_after:wN \fp_level_input_exponents_b: + \tex_expandafter:D \fp_level_input_exponents_b: \tex_fi:D } \cs_new_protected_nopar:Npn @@ -1263,7 +1398,7 @@ \tl_set:Nx \l_fp_tmp_tl { #9 - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int } \l_fp_input_a_decimal_int \l_fp_tmp_tl \scan_stop: @@ -1277,7 +1412,7 @@ %\end{macro} % %\begin{macro}{\fp_tmp:w} -% Used for output of results, cutting down on \cs{exp_after:wN}. +% Used for output of results, cutting down on \cs{tex_expandafter:D}. % This is just a place holder definition. % \begin{macrocode} \cs_new_protected_nopar:Npn \fp_tmp:w #1#2 { } @@ -1307,6 +1442,26 @@ %\end{macro} %\end{macro} % +%\begin{macro}{\fp_const:Nn} +%\begin{macro}{\fp_const:cn} +% A simple wrapper. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_const:Nn #1#2 { + \cs_if_free:NTF #1 + { + \fp_new:N #1 + \fp_gset:Nn #1 {#2} + } + { + \msg_kernel_error:nx { variable-already-defined } + { \token_to_str:N #1 } + } +} +\cs_generate_variant:Nn \fp_const:Nn { c } +% \end{macrocode} +%\end{macro} +%\end{macro} +% %\begin{macro}{\fp_zero:N} %\begin{macro}{\fp_zero:c} %\begin{macro}{\fp_gzero:N} @@ -1364,7 +1519,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -1408,7 +1563,7 @@ \l_fp_tmp_dim \l_fp_tmp_skip \fp_split:Nn a { - \exp_after:wN \fp_set_from_dim_aux:w + \tex_expandafter:D \fp_set_from_dim_aux:w \dim_use:N \l_fp_tmp_dim } \fp_standardise:NNNN @@ -1429,7 +1584,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -1517,7 +1672,7 @@ % work out how big the input is. % \begin{macrocode} \cs_new_nopar:Npn \fp_use:N #1 { - \exp_after:wN \fp_use_aux:w #1 \q_stop + \tex_expandafter:D \fp_use_aux:w #1 \q_stop } \cs_generate_variant:Nn \fp_use:N { c } \cs_new_nopar:Npn \fp_use_aux:w #1#2 e #3 \q_stop { @@ -1525,13 +1680,13 @@ - \tex_fi:D \tex_ifnum:D #3 > \c_zero - \exp_after:wN \fp_use_large:w + \tex_expandafter:D \fp_use_large:w \tex_else:D \tex_ifnum:D #3 < \c_zero - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_use_small:w \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_use_none:w \tex_fi:D \tex_fi:D @@ -1556,9 +1711,9 @@ % \begin{macrocode} \cs_new_nopar:Npn \fp_use_large:w #1 . #2 e #3 \q_stop { \tex_ifnum:D #3 < \c_ten - \exp_after:wN \fp_use_large_aux_i:w + \tex_expandafter:D \fp_use_large_aux_i:w \tex_else:D - \exp_after:wN \fp_use_large_aux_ii:w + \tex_expandafter:D \fp_use_large_aux_ii:w \tex_fi:D #1#2 e #3 \q_stop } @@ -1651,7 +1806,7 @@ % simply using floating point variables, particularly in the lead-off. % \begin{macrocode} \cs_new_nopar:Npn \fp_to_int:N #1 { - \exp_after:wN \fp_to_int_aux:w #1 \q_stop + \tex_expandafter:D \fp_to_int_aux:w #1 \q_stop } \cs_generate_variant:Nn \fp_to_int:N { c } \cs_new_nopar:Npn \fp_to_int_aux:w #1#2 e #3 \q_stop { @@ -1659,9 +1814,9 @@ - \tex_fi:D \tex_ifnum:D #3 < \c_zero - \exp_after:wN \fp_to_int_small:w + \tex_expandafter:D \fp_to_int_small:w \tex_else:D - \exp_after:wN \fp_to_int_large:w + \tex_expandafter:D \fp_to_int_large:w \tex_fi:D #2 e #3 \q_stop } @@ -1685,9 +1840,9 @@ % \begin{macrocode} \cs_new_nopar:Npn \fp_to_int_large:w #1 . #2 e #3 \q_stop { \tex_ifnum:D #3 < \c_ten - \exp_after:wN \fp_to_int_large_aux_i:w + \tex_expandafter:D \fp_to_int_large_aux_i:w \tex_else:D - \exp_after:wN \fp_to_int_large_aux_ii:w + \tex_expandafter:D \fp_to_int_large_aux_ii:w \tex_fi:D #1#2 e #3 \q_stop } @@ -1783,7 +1938,7 @@ % simply using floating point variables, particularly in the lead-off. % \begin{macrocode} \cs_new_nopar:Npn \fp_to_tl:N #1 { - \exp_after:wN \fp_to_tl_aux:w #1 \q_stop + \tex_expandafter:D \fp_to_tl_aux:w #1 \q_stop } \cs_generate_variant:Nn \fp_to_tl:N { c } \cs_new_nopar:Npn \fp_to_tl_aux:w #1#2 e #3 \q_stop { @@ -1791,9 +1946,9 @@ - \tex_fi:D \tex_ifnum:D #3 < \c_zero - \exp_after:wN \fp_to_tl_small:w + \tex_expandafter:D \fp_to_tl_small:w \tex_else:D - \exp_after:wN \fp_to_tl_large:w + \tex_expandafter:D \fp_to_tl_large:w \tex_fi:D #2 e #3 \q_stop } @@ -1806,9 +1961,9 @@ % \begin{macrocode} \cs_new_nopar:Npn \fp_to_tl_large:w #1 e #2 \q_stop { \tex_ifnum:D #2 < \c_ten - \exp_after:wN \fp_to_tl_large_aux_i:w + \tex_expandafter:D \fp_to_tl_large_aux_i:w \tex_else:D - \exp_after:wN \fp_to_tl_large_aux_ii:w + \tex_expandafter:D \fp_to_tl_large_aux_ii:w \tex_fi:D #1 e #2 \q_stop } @@ -1870,13 +2025,13 @@ % \begin{macrocode} \cs_new_nopar:Npn \fp_to_tl_small:w #1 e #2 \q_stop { \tex_ifnum:D #2 = \c_minus_one - \exp_after:wN \fp_to_tl_small_one:w + \tex_expandafter:D \fp_to_tl_small_one:w \tex_else:D \tex_ifnum:D #2 = -\c_two - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_to_tl_small_two:w \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_to_tl_small_aux:w \tex_fi:D \tex_fi:D @@ -1888,7 +2043,7 @@ \etex_numexpr:D #1 \fp_use_i_to_iix:NNNNNNNNN #2 + 1 < \c_one_thousand_million 0. - \exp_after:wN \fp_to_tl_small_zeros:NNNNNNNNN + \tex_expandafter:D \fp_to_tl_small_zeros:NNNNNNNNN \tex_number:D \etex_numexpr:D #1 \fp_use_i_to_iix:NNNNNNNNN #2 + 1 @@ -1907,7 +2062,7 @@ \etex_numexpr:D #1 \fp_use_i_to_vii:NNNNNNNNN #2 0 + \c_ten < \c_one_thousand_million 0.0 - \exp_after:wN \fp_to_tl_small_zeros:NNNNNNNNN + \tex_expandafter:D \fp_to_tl_small_zeros:NNNNNNNNN \tex_number:D \etex_numexpr:D #1 \fp_use_i_to_vii:NNNNNNNNN #2 0 + \c_ten @@ -2073,7 +2228,7 @@ \fp_read:N #2 \int_set:Nn \l_fp_round_target_int { #3 - 1 } \tex_ifnum:D \l_fp_round_target_int < \c_ten - \exp_after:wN \fp_round: + \tex_expandafter:D \fp_round: \tex_fi:D \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million \cs_set_protected_nopar:Npx \fp_tmp:w @@ -2088,7 +2243,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -2125,7 +2280,7 @@ \int_set:Nn \l_fp_round_target_int { #3 + \l_fp_input_a_exponent_int } \tex_ifnum:D \l_fp_round_target_int < \c_ten - \exp_after:wN \fp_round: + \tex_expandafter:D \fp_round: \tex_fi:D \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million \cs_set_protected_nopar:Npx \fp_tmp:w @@ -2140,7 +2295,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -2170,7 +2325,7 @@ \l_fp_round_position_int \c_eight \tl_clear:N \l_fp_round_decimal_tl \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_round_aux:NNNNNNNNN \int_use:N \l_fp_input_a_decimal_int } \cs_new_protected_nopar:Npn \fp_round_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { @@ -2207,7 +2362,7 @@ \tex_fi:D \tex_advance:D \l_fp_round_position_int \c_minus_one \tex_ifnum:D \l_fp_round_position_int > \c_minus_one - \exp_after:wN \fp_round_loop:N + \tex_expandafter:D \fp_round_loop:N \tex_fi:D } % \end{macrocode} @@ -2245,7 +2400,7 @@ + \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -2289,13 +2444,13 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int } - \exp_after:wN \group_end: \exp_after:wN - #1 \exp_after:wN #2 \exp_after:wN { \l_fp_tmp_tl } + \tex_expandafter:D \group_end: \tex_expandafter:D + #1 \tex_expandafter:D #2 \tex_expandafter:D { \l_fp_tmp_tl } } % \end{macrocode} %\end{macro} @@ -2351,9 +2506,9 @@ \l_fp_input_a_sign_int * \l_fp_input_b_sign_int \scan_stop: > \c_zero - \exp_after:wN \fp_add_sum: + \tex_expandafter:D \fp_add_sum: \tex_else:D - \exp_after:wN \fp_add_difference: + \tex_expandafter:D \fp_add_difference: \tex_fi:D \l_fp_output_exponent_int \l_fp_input_a_exponent_int \fp_standardise:NNNN @@ -2373,7 +2528,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million e @@ -2490,7 +2645,7 @@ %\begin{macro}{\fp_gmul:Nn} %\begin{macro}{\fp_gmul:cn} %\begin{macro}[aux]{\fp_mul_aux:NNn} -%\begin{macro}[aux]{\fp_mul_int:} +%\begin{macro}[aux]{\fp_mul_internal:} %\begin{macro}[aux]{\fp_mul_split:NNNN} %\begin{macro}[aux]{\fp_mul_split:w} %\begin{macro}[aux]{\fp_mul_end_level:} @@ -2522,7 +2677,7 @@ \l_fp_input_b_integer_int \l_fp_input_b_decimal_int \l_fp_input_b_exponent_int - \fp_mul_int: + \fp_mul_internal: \l_fp_output_exponent_int \etex_numexpr:D \l_fp_input_a_exponent_int + \l_fp_input_b_exponent_int @@ -2554,7 +2709,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million e @@ -2566,7 +2721,7 @@ % \end{macrocode} % Done separately so that the internal use is a bit easier. % \begin{macrocode} -\cs_new_protected_nopar:Npn \fp_mul_int: { +\cs_new_protected_nopar:Npn \fp_mul_internal: { \fp_mul_split:NNNN \l_fp_input_a_decimal_int \l_fp_mul_a_i_int \l_fp_mul_a_ii_int \l_fp_mul_a_iii_int \fp_mul_split:NNNN \l_fp_input_b_decimal_int @@ -2610,7 +2765,7 @@ #3 ##5##6##7 \scan_stop: #4 ##8##9 \scan_stop: } - \exp_after:wN \fp_mul_split_aux:w \int_use:N #1 \q_stop + \tex_expandafter:D \fp_mul_split_aux:w \int_use:N #1 \q_stop \tex_advance:D #1 -\c_one_thousand_million } \cs_new_protected_nopar:Npn \fp_mul_product:NN #1#2 { @@ -2624,7 +2779,7 @@ % \begin{macrocode} \cs_new_protected_nopar:Npn \fp_mul_end_level: { \tex_advance:D \l_fp_mul_output_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_mul_end_level:NNNNNNNNN \int_use:N \l_fp_mul_output_int } \cs_new_protected_nopar:Npn \fp_mul_end_level:NNNNNNNNN @@ -2649,7 +2804,7 @@ %\begin{macro}{\fp_gdiv:Nn} %\begin{macro}{\fp_gdiv:cn} %\begin{macro}[aux]{\fp_div_aux:NNn} -%\begin{macro}[aux]{\fp_div_aux:} +%\begin{macro}{\fp_div_internal:} %\begin{macro}[aux]{\fp_div_loop:} %\begin{macro}[aux]{\fp_div_divide:} %\begin{macro}[aux]{\fp_div_divide_aux:} @@ -2666,7 +2821,6 @@ } \cs_generate_variant:Nn \fp_div:Nn { c } \cs_generate_variant:Nn \fp_gdiv:Nn { c } - % \end{macrocode} % Division proper starts with a couple of tests. If the denominator is % zero then a error is issued. On the other hand, if the numerator is @@ -2702,8 +2856,8 @@ #1 \exp_not:N #2 { \c_zero_fp } } \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN - \fp_div_aux: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_div_internal: \tex_fi:D \tex_fi:D \fp_tmp:w #1#2 @@ -2717,7 +2871,7 @@ % decimal place. Most of the process takes place in the loop function % below. % \begin{macrocode} -\cs_new_protected_nopar:Npn \fp_div_aux: { +\cs_new_protected_nopar:Npn \fp_div_internal: { \l_fp_output_integer_int \c_zero \l_fp_output_decimal_int \c_zero \cs_set_eq:NN \fp_div_store: \fp_div_store_integer: @@ -2754,7 +2908,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million \scan_stop: @@ -2774,14 +2928,14 @@ \fp_div_store: \tex_multiply:D \l_fp_input_a_integer_int \c_ten \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million - \exp_after:wN \fp_div_loop_step:w + \tex_expandafter:D \fp_div_loop_step:w \int_use:N \l_fp_input_a_decimal_int \q_stop \tex_ifnum:D \etex_numexpr:D \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int > \c_zero \tex_ifnum:D \l_fp_div_offset_int > \c_zero - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_div_loop: \tex_fi:D \tex_fi:D @@ -2795,16 +2949,16 @@ % \begin{macrocode} \cs_new_protected_nopar:Npn \fp_div_divide: { \tex_ifnum:D \l_fp_input_a_integer_int > \l_fp_input_b_integer_int - \exp_after:wN \fp_div_divide_aux: + \tex_expandafter:D \fp_div_divide_aux: \tex_else:D \tex_ifnum:D \l_fp_input_a_integer_int < \l_fp_input_b_integer_int \tex_else:D \tex_ifnum:D \l_fp_input_a_decimal_int < \l_fp_input_b_decimal_int \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN - \exp_after:wN \exp_after:wN \exp_after:wN - \exp_after:wN \fp_div_divide_aux: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_div_divide_aux: \tex_fi:D \tex_fi:D \tex_fi:D @@ -2960,6 +3114,7 @@ \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_iv_int \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_iii_int \fp_mul_product:NN \l_fp_mul_a_iv_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_v_int \l_fp_mul_b_i_int \fp_mul_end_level: \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_iv_int \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_iii_int @@ -2983,6 +3138,73 @@ % \end{macrocode} %\end{macro} % +%\begin{macro}{\fp_mul:NNNNNNNNN} +% For internal multiplication where the integer does need to be +% retained. This means of course that this code is quite slow, and so +% is only used when necessary. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_mul:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \fp_mul_split:NNNN #2 + \l_fp_mul_a_i_int \l_fp_mul_a_ii_int \l_fp_mul_a_iii_int + \fp_mul_split:NNNN #3 + \l_fp_mul_a_iv_int \l_fp_mul_a_v_int \l_fp_mul_a_vi_int + \fp_mul_split:NNNN #5 + \l_fp_mul_b_i_int \l_fp_mul_b_ii_int \l_fp_mul_b_iii_int + \fp_mul_split:NNNN #6 + \l_fp_mul_b_iv_int \l_fp_mul_b_v_int \l_fp_mul_b_vi_int + \l_fp_mul_output_int \c_zero + \tl_clear:N \l_fp_mul_output_tl + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_vi_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_v_int + \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_iv_int + \fp_mul_product:NN \l_fp_mul_a_iv_int \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_v_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_vi_int \l_fp_mul_b_i_int + \tex_divide:D \l_fp_mul_output_int \c_one_thousand + \fp_mul_product:NN #1 \l_fp_mul_b_vi_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_v_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_iv_int + \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_iv_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_v_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_vi_int #4 + \fp_mul_end_level: + \fp_mul_product:NN #1 \l_fp_mul_b_v_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_iv_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_iv_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_v_int #4 + \fp_mul_end_level: + \fp_mul_product:NN #1 \l_fp_mul_b_iv_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_iv_int #4 + \fp_mul_end_level: + #9 0 \l_fp_mul_output_tl \scan_stop: + \tl_clear:N \l_fp_mul_output_tl + \fp_mul_product:NN #1 \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_iii_int #4 + \fp_mul_end_level: + \fp_mul_product:NN #1 \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_ii_int #4 + \fp_mul_end_level: + \fp_mul_product:NN #1 \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_i_int #4 + \fp_mul_end_level: + #8 0 \l_fp_mul_output_tl \scan_stop: + \tl_clear:N \l_fp_mul_output_tl + \fp_mul_product:NN #1 #4 + \fp_mul_end_level: + #7 0 \l_fp_mul_output_tl \scan_stop: +} +% \end{macrocode} +%\end{macro} +% %\begin{macro}{\fp_div_integer:NNNNN} % Here, division is always by an integer, and so it is possible to % use \TeX's native calculations rather than doing it in macros. @@ -3008,66 +3230,59 @@ } % \end{macrocode} %\end{macro} -% -%\subsection{Trigonometric functions} % -%\begin{macro}{\fp_trig_normalise:} -%\begin{macro}[aux]{\fp_trig_normalise_aux_i:} -%\begin{macro}[aux]{\fp_trig_normalise_aux:w} -%\begin{macro}[aux]{\fp_trig_normalise_aux_ii:} -%\begin{macro}[aux]{\fp_trig_normalise_aux:NNNNNNNNN} -%\begin{macro}[aux]{\fp_trig_normalise_aux_iii:} -% For normalisation, the code essentially switches to fixed-point -% arithmetic. There is a shift of the exponent, then repeated -% subtractions. The end result is a number in the range -% \( -\pi < x \le \pi \). +%\begin{macro}{\fp_extended_normalise:} +%\begin{macro}[aux]{\fp_extended_normalise_aux_i:} +%\begin{macro}[aux]{\fp_extended_normalise_aux_i:w} +%\begin{macro}[aux]{\fp_extended_normalise_aux_ii:w} +%\begin{macro}[aux]{\fp_extended_normalise_aux_ii:} +%\begin{macro}[aux]{\fp_extended_normalise_aux:NNNNNNNNN} +% The `extended' integers for internal use are mainly used in +% fixed-point mode. This comes up in a few places, so a generalised +% utility is made available to carry out the change. This function +% simply calls the two loops to shift the input to the point of +% having a zero exponent. % \begin{macrocode} -\cs_new_protected_nopar:Npn \fp_trig_normalise: { - \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten - \l_fp_input_a_extended_int \c_zero - \fp_trig_normalise_aux_i: - \fp_trig_normalise_aux_ii: - \fp_trig_normalise_aux_iii: - \tex_ifnum:D \l_fp_input_a_integer_int < \c_zero - \l_fp_input_a_sign_int -\l_fp_input_a_sign_int - \l_fp_input_a_integer_int -\l_fp_input_a_integer_int - \tex_fi:D - \exp_after:wN \fp_trig_octant: - \tex_else:D - \l_fp_input_a_sign_int \c_one - \l_fp_output_integer_int \c_zero - \l_fp_output_decimal_int \c_zero - \l_fp_output_exponent_int \c_zero - \exp_after:wN \fp_trig_overflow_msg: - \tex_fi:D +\cs_new_protected_nopar:Npn \fp_extended_normalise: { + \fp_extended_normalise_aux_i: + \fp_extended_normalise_aux_ii: } -\cs_new_protected_nopar:Npn \fp_trig_normalise_aux_i: { +\cs_new_protected_nopar:Npn \fp_extended_normalise_aux_i: { \tex_ifnum:D \l_fp_input_a_exponent_int > \c_zero \tex_multiply:D \l_fp_input_a_integer_int \c_ten \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million - \exp_after:wN \fp_trig_normalise_aux:w + \tex_expandafter:D \fp_extended_normalise_aux_i:w \int_use:N \l_fp_input_a_decimal_int \q_stop - \exp_after:wN \fp_trig_normalise_aux_i: + \tex_expandafter:D \fp_extended_normalise_aux_i: \tex_fi:D } \cs_new_protected_nopar:Npn - \fp_trig_normalise_aux:w #1#2#3#4#5#6#7#8#9 \q_stop { + \fp_extended_normalise_aux_i:w #1#2#3#4#5#6#7#8#9 \q_stop { \l_fp_input_a_integer_int \etex_numexpr:D \l_fp_input_a_integer_int + #2 \scan_stop: \l_fp_input_a_decimal_int #3#4#5#6#7#8#9 0 \scan_stop: + \tex_advance:D \l_fp_input_a_extended_int \c_one_thousand_million + \tex_expandafter:D \fp_extended_normalise_aux_ii:w + \int_use:N \l_fp_input_a_extended_int \q_stop +} +\cs_new_protected_nopar:Npn + \fp_extended_normalise_aux_ii:w #1#2#3#4#5#6#7#8#9 \q_stop { + \l_fp_input_a_decimal_int + \etex_numexpr:D \l_fp_input_a_decimal_int + #2 \scan_stop: + \l_fp_input_a_extended_int #3#4#5#6#7#8#9 0 \scan_stop: \tex_advance:D \l_fp_input_a_exponent_int \c_minus_one } -\cs_new_protected_nopar:Npn \fp_trig_normalise_aux_ii: { +\cs_new_protected_nopar:Npn \fp_extended_normalise_aux_ii: { \tex_ifnum:D \l_fp_input_a_exponent_int < \c_zero \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN - \fp_trig_normalise_aux:NNNNNNNNN + \tex_expandafter:D \use_i:nn \tex_expandafter:D + \fp_extended_normalise_ii_aux:NNNNNNNNN \int_use:N \l_fp_input_a_decimal_int - \exp_after:wN \fp_trig_normalise_aux_ii: + \tex_expandafter:D \fp_extended_normalise_aux_ii: \tex_fi:D } \cs_new_protected_nopar:Npn - \fp_trig_normalise_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \fp_extended_normalise_ii_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { \tex_ifnum:D \l_fp_input_a_integer_int = \c_zero \l_fp_input_a_decimal_int #1#2#3#4#5#6#7#8 \scan_stop: \tex_else:D @@ -3088,7 +3303,95 @@ \l_fp_input_a_extended_int \l_fp_tmp_tl \scan_stop: \tex_advance:D \l_fp_input_a_exponent_int \c_one } -\cs_new_protected_nopar:Npn \fp_trig_normalise_aux_iii: { +% \end{macrocode} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +% +%\begin{macro}{\fp_extended_normalise_output:} +%\begin{macro}[aux]{\fp_extended_normalise_output_aux_i:NNNNNNNNN} +%\begin{macro}[aux]{\fp_extended_normalise_output_aux_ii:NNNNNNNNN} +%\begin{macro}[aux]{\fp_extended_normalise_output_aux:N} +% At some stages in working out extended output, it is possible for the +% value to need shifting to keep the integer part in range. This only +% ever happens such that the integer needs to be made smaller. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_extended_normalise_output: { + \tex_ifnum:D \l_fp_output_integer_int > \c_nine + \tex_advance:D \l_fp_output_integer_int \c_one_thousand_million + \tex_expandafter:D \use_i:nn \tex_expandafter:D + \fp_extended_normalise_output_aux_i:NNNNNNNNN + \int_use:N \l_fp_output_integer_int + \tex_expandafter:D \fp_extended_normalise_output: + \tex_fi:D +} +\cs_new_protected_nopar:Npn + \fp_extended_normalise_output_aux_i:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \l_fp_output_integer_int #1#2#3#4#5#6#7#8 \scan_stop: + \tex_advance:D \l_fp_output_decimal_int \c_one_thousand_million + \tl_set:Nx \l_fp_tmp_tl + { + #9 + \tex_expandafter:D \use_none:n + \int_use:N \l_fp_output_decimal_int + } + \tex_expandafter:D \fp_extended_normalise_output_aux_ii:NNNNNNNNN + \l_fp_tmp_tl +} +\cs_new_protected_nopar:Npn + \fp_extended_normalise_output_aux_ii:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \l_fp_output_decimal_int #1#2#3#4#5#6#7#8#9 \scan_stop: + \fp_extended_normalise_output_aux:N +} +\cs_new_protected_nopar:Npn \fp_extended_normalise_output_aux:N #1 { + \tex_advance:D \l_fp_output_extended_int \c_one_thousand_million + \tex_divide:D \l_fp_output_extended_int \c_ten + \tl_set:Nx \l_fp_tmp_tl + { + #1 + \tex_expandafter:D \use_none:n + \int_use:N \l_fp_output_extended_int + } + \l_fp_output_extended_int \l_fp_tmp_tl \scan_stop: + \tex_advance:D \l_fp_output_exponent_int \c_one +} +% \end{macrocode} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +% +%\subsection{Trigonometric functions} +% +%\begin{macro}{\fp_trig_normalise:} +%\begin{macro}[aux]{\fp_trig_normalise_aux:} +% For normalisation, the code essentially switches to fixed-point +% arithmetic. There is a shift of the exponent, then repeated +% subtractions. The end result is a number in the range +% \( -\pi < x \le \pi \). +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_trig_normalise: { + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten + \l_fp_input_a_extended_int \c_zero + \fp_extended_normalise: + \fp_trig_normalise_aux: + \tex_ifnum:D \l_fp_input_a_integer_int < \c_zero + \l_fp_input_a_sign_int -\l_fp_input_a_sign_int + \l_fp_input_a_integer_int -\l_fp_input_a_integer_int + \tex_fi:D + \tex_expandafter:D \fp_trig_octant: + \tex_else:D + \l_fp_input_a_sign_int \c_one + \l_fp_output_integer_int \c_zero + \l_fp_output_decimal_int \c_zero + \l_fp_output_exponent_int \c_zero + \tex_expandafter:D \fp_trig_overflow_msg: + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_trig_normalise_aux: { \tex_ifnum:D \l_fp_input_a_integer_int > \c_three \fp_sub:NNNNNNNNN \l_fp_input_a_integer_int \l_fp_input_a_decimal_int @@ -3096,7 +3399,7 @@ \c_six \c_fp_two_pi_decimal_int \c_fp_two_pi_extended_int \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_extended_int - \exp_after:wN \fp_trig_normalise_aux_iii: + \tex_expandafter:D \fp_trig_normalise_aux: \tex_else:D \tex_ifnum:D \l_fp_input_a_integer_int > \c_two \tex_ifnum:D \l_fp_input_a_decimal_int > \c_fp_pi_decimal_int @@ -3106,9 +3409,9 @@ \c_six \c_fp_two_pi_decimal_int \c_fp_two_pi_extended_int \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_extended_int - \exp_after:wN \exp_after:wN \exp_after:wN - \exp_after:wN \exp_after:wN \exp_after:wN - \exp_after:wN \fp_trig_normalise_aux_iii: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_trig_normalise_aux: \tex_fi:D \tex_fi:D \tex_fi:D @@ -3116,10 +3419,6 @@ % \end{macrocode} %\end{macro} %\end{macro} -%\end{macro} -%\end{macro} -%\end{macro} -%\end{macro} % %\begin{macro}{\fp_trig_octant:} %\begin{macro}[aux]{\fp_trig_octant_aux:} @@ -3157,7 +3456,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_extended_int \tex_advance:D \l_fp_trig_octant_int \c_one - \exp_after:wN \fp_trig_octant_aux: + \tex_expandafter:D \fp_trig_octant_aux: \tex_else:D \tex_ifnum:D \l_fp_input_a_decimal_int > \c_fp_pi_by_four_decimal_int @@ -3169,7 +3468,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_extended_int \tex_advance:D \l_fp_trig_octant_int \c_one - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_trig_octant_aux: \tex_fi:D \tex_fi:D @@ -3211,7 +3510,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_exponent_int - \tl_set:Nx \l_fp_trig_arg_tl + \tl_set:Nx \l_fp_arg_tl { \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero - @@ -3220,7 +3519,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_input_a_decimal_int + \c_one_thousand_million e @@ -3230,21 +3529,21 @@ \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: - #1 \exp_not:N #2 { \l_fp_trig_arg_tl } + #1 \exp_not:N #2 { \l_fp_arg_tl } } \tex_else:D \etex_ifcsname:D - c_fp_sin ( \l_fp_trig_arg_tl ) _tl + c_fp_sin ( \l_fp_arg_tl ) _fp \tex_endcsname:D \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_sin_aux_i: \tex_fi:D \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: #1 \exp_not:N #2 - { \use:c { c_fp_sin ( \l_fp_trig_arg_tl ) _tl } } + { \use:c { c_fp_sin ( \l_fp_arg_tl ) _fp } } } \tex_fi:D \fp_tmp:w @@ -3270,8 +3569,8 @@ \l_fp_output_integer_int \l_fp_output_decimal_int \l_fp_output_exponent_int - \tl_new:c { c_fp_sin ( \l_fp_trig_arg_tl ) _tl } - \tl_gset:cx { c_fp_sin ( \l_fp_trig_arg_tl ) _tl } + \tl_new:c { c_fp_sin ( \l_fp_arg_tl ) _fp } + \tl_gset:cx { c_fp_sin ( \l_fp_arg_tl ) _fp } { \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + @@ -3280,7 +3579,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million \scan_stop: @@ -3291,13 +3590,13 @@ \cs_new_protected_nopar:Npn \fp_sin_aux_ii: { \tex_ifcase:D \l_fp_trig_octant_int \tex_or:D - \exp_after:wN \fp_trig_calc_sin: + \tex_expandafter:D \fp_trig_calc_sin: \tex_or:D - \exp_after:wN \fp_trig_calc_cos: + \tex_expandafter:D \fp_trig_calc_cos: \tex_or:D - \exp_after:wN \fp_trig_calc_cos: + \tex_expandafter:D \fp_trig_calc_cos: \tex_or:D - \exp_after:wN \fp_trig_calc_sin: + \tex_expandafter:D \fp_trig_calc_sin: \tex_fi:D } % \end{macrocode} @@ -3334,7 +3633,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_exponent_int - \tl_set:Nx \l_fp_trig_arg_tl + \tl_set:Nx \l_fp_arg_tl { \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero - @@ -3343,21 +3642,21 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_input_a_decimal_int + \c_one_thousand_million e \int_use:N \l_fp_input_a_exponent_int } - \etex_ifcsname:D c_fp_cos ( \l_fp_trig_arg_tl ) _tl \tex_endcsname:D + \etex_ifcsname:D c_fp_cos ( \l_fp_arg_tl ) _fp \tex_endcsname:D \tex_else:D - \exp_after:wN \fp_cos_aux_i: + \tex_expandafter:D \fp_cos_aux_i: \tex_fi:D \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: #1 \exp_not:N #2 - { \use:c { c_fp_cos ( \l_fp_trig_arg_tl ) _tl } } + { \use:c { c_fp_cos ( \l_fp_arg_tl ) _fp } } } \fp_tmp:w } @@ -3380,8 +3679,8 @@ \l_fp_output_integer_int \l_fp_output_decimal_int \l_fp_output_exponent_int - \tl_new:c { c_fp_cos ( \l_fp_trig_arg_tl ) _tl } - \tl_gset:cx { c_fp_cos ( \l_fp_trig_arg_tl ) _tl } + \tl_new:c { c_fp_cos ( \l_fp_arg_tl ) _fp } + \tl_gset:cx { c_fp_cos ( \l_fp_arg_tl ) _fp } { \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + @@ -3390,7 +3689,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million \scan_stop: @@ -3401,13 +3700,13 @@ \cs_new_protected_nopar:Npn \fp_cos_aux_ii: { \tex_ifcase:D \l_fp_trig_octant_int \tex_or:D - \exp_after:wN \fp_trig_calc_cos: + \tex_expandafter:D \fp_trig_calc_cos: \tex_or:D - \exp_after:wN \fp_trig_calc_sin: + \tex_expandafter:D \fp_trig_calc_sin: \tex_or:D - \exp_after:wN \fp_trig_calc_sin: + \tex_expandafter:D \fp_trig_calc_sin: \tex_or:D - \exp_after:wN \fp_trig_calc_cos: + \tex_expandafter:D \fp_trig_calc_cos: \tex_fi:D \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero \tex_ifnum:D \l_fp_trig_octant_int > \c_two @@ -3431,7 +3730,7 @@ % %\begin{macro}{\fp_trig_calc_cos:} %\begin{macro}{\fp_trig_calc_sin:} -%\begin{macro}[aux]{\fp_trig_calc_aux:} +%\begin{macro}[aux]{\fp_trig_calc_Taylor:} % These functions actually do the calculation for sine and cosine. % \begin{macrocode} \cs_new_protected_nopar:Npn \fp_trig_calc_cos: { @@ -3466,7 +3765,7 @@ \tex_fi:D \tex_advance:D \l_fp_output_extended_int -\l_fp_trig_extended_int \tex_advance:D \l_fp_output_decimal_int -\l_fp_trig_decimal_int - \exp_after:wN \fp_trig_calc_aux: + \tex_expandafter:D \fp_trig_calc_Taylor: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_trig_calc_sin: { @@ -3480,7 +3779,7 @@ \l_fp_trig_decimal_int \l_fp_input_a_decimal_int \l_fp_trig_extended_int \l_fp_input_a_extended_int \l_fp_count_int \c_two - \exp_after:wN \fp_trig_calc_aux: + \tex_expandafter:D \fp_trig_calc_Taylor: \tex_fi:D } % \end{macrocode} @@ -3488,7 +3787,7 @@ % functions. Lots of shuffling about as \TeX\ is not exactly a natural % choice for this sort of thing. % \begin{macrocode} -\cs_new_protected_nopar:Npn \fp_trig_calc_aux: { +\cs_new_protected_nopar:Npn \fp_trig_calc_Taylor: { \l_fp_trig_sign_int -\l_fp_trig_sign_int \fp_mul:NNNNNN \l_fp_trig_decimal_int \l_fp_trig_extended_int @@ -3538,7 +3837,7 @@ \tex_advance:D \l_fp_output_decimal_int \c_one_thousand_million \tex_fi:D \tex_fi:D - \exp_after:wN \fp_trig_calc_aux: + \tex_expandafter:D \fp_trig_calc_Taylor: \tex_fi:D } % \end{macrocode} @@ -3577,7 +3876,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_exponent_int - \tl_set:Nx \l_fp_trig_arg_tl + \tl_set:Nx \l_fp_arg_tl { \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero - @@ -3586,7 +3885,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_input_a_decimal_int + \c_one_thousand_million e @@ -3596,21 +3895,21 @@ \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: - #1 \exp_not:N #2 { \l_fp_trig_arg_tl } + #1 \exp_not:N #2 { \l_fp_arg_tl } } \tex_else:D \etex_ifcsname:D - c_fp_tan ( \l_fp_trig_arg_tl ) _tl + c_fp_tan ( \l_fp_arg_tl ) _fp \tex_endcsname:D \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_tan_aux_i: \tex_fi:D \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: #1 \exp_not:N #2 - { \use:c { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } } + { \use:c { c_fp_tan ( \l_fp_arg_tl ) _fp } } } \tex_fi:D \fp_tmp:w @@ -3624,11 +3923,11 @@ % \begin{macrocode} \cs_new_protected_nopar:Npn \fp_tan_aux_i: { \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten - \exp_after:wN \fp_tan_aux_ii: + \tex_expandafter:D \fp_tan_aux_ii: \tex_else:D - \cs_new_eq:cN { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } + \cs_new_eq:cN { c_fp_tan ( \l_fp_arg_tl ) _fp } \c_zero_fp - \exp_after:wN \fp_trig_overflow_msg: + \tex_expandafter:D \fp_trig_overflow_msg: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_tan_aux_ii: { @@ -3636,14 +3935,14 @@ \fp_cos_aux_ii: \tex_ifnum:D \l_fp_input_a_decimal_int = \c_zero \tex_ifnum:D \l_fp_input_a_integer_int = \c_zero - \cs_new_eq:cN { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } + \cs_new_eq:cN { c_fp_tan ( \l_fp_arg_tl ) _fp } \c_undefined_fp \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_tan_aux_iii: \tex_fi:D \tex_else:D - \exp_after:wN \fp_tan_aux_iii: + \tex_expandafter:D \fp_tan_aux_iii: \tex_fi:D } % \end{macrocode} @@ -3671,14 +3970,14 @@ \l_fp_input_a_exponent_int \tex_ifnum:D \l_fp_input_a_decimal_int = \c_zero \tex_ifnum:D \l_fp_input_a_integer_int = \c_zero - \cs_new_eq:cN { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } + \cs_new_eq:cN { c_fp_tan ( \l_fp_arg_tl ) _fp } \c_zero_fp \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_tan_aux_iv: \tex_fi:D \tex_else:D - \exp_after:wN \fp_tan_aux_iv: + \tex_expandafter:D \fp_tan_aux_iv: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_tan_aux_iv: { @@ -3701,8 +4000,8 @@ \l_fp_output_integer_int \l_fp_output_decimal_int \l_fp_output_exponent_int - \tl_new:c { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } - \tl_gset:cx { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } + \tl_new:c { c_fp_tan ( \l_fp_arg_tl ) _fp } + \tl_gset:cx { c_fp_tan ( \l_fp_arg_tl ) _fp } { \tex_ifnum:D \l_fp_output_sign_int > \c_zero + @@ -3711,7 +4010,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million \scan_stop: @@ -3730,43 +4029,1462 @@ %\end{macro} %\end{macro} % -%\subsection{Tests for special values} -% -%\begin{macro}{\fp_if_undefined_p:N} -%\begin{macro}[TF]{\fp_if_undefined:N} -% Testing for an undefined value is easy. +%\subsection{Exponent and logarithm functions} +% +%\begin{macro}{\c_fp_exp_1_tl} +%\begin{macro}{\c_fp_exp_2_tl} +%\begin{macro}{\c_fp_exp_3_tl} +%\begin{macro}{\c_fp_exp_4_tl} +%\begin{macro}{\c_fp_exp_5_tl} +%\begin{macro}{\c_fp_exp_6_tl} +%\begin{macro}{\c_fp_exp_7_tl} +%\begin{macro}{\c_fp_exp_8_tl} +%\begin{macro}{\c_fp_exp_9_tl} +%\begin{macro}{\c_fp_exp_10_tl} +%\begin{macro}{\c_fp_exp_20_tl} +%\begin{macro}{\c_fp_exp_30_tl} +%\begin{macro}{\c_fp_exp_40_tl} +%\begin{macro}{\c_fp_exp_50_tl} +%\begin{macro}{\c_fp_exp_60_tl} +%\begin{macro}{\c_fp_exp_70_tl} +%\begin{macro}{\c_fp_exp_80_tl} +%\begin{macro}{\c_fp_exp_90_tl} +%\begin{macro}{\c_fp_exp_100_tl} +%\begin{macro}{\c_fp_exp_200_tl} +% Calculation of exponentials requires a number of precomputed values: +% first the positive integers. % \begin{macrocode} -\prg_new_conditional:Npnn \fp_if_undefined:N #1 { p , T , F , TF } { - \tex_ifx:D #1 \c_undefined_fp - \prg_return_true: - \tex_else:D - \prg_return_false: - \tex_fi:D -} +\tl_new:c { c_fp_exp_1_tl } +\tl_set:cn { c_fp_exp_1_tl } + { { 2 } { 718281828 } { 459045235 } { 0 } } +\tl_new:c { c_fp_exp_2_tl } +\tl_set:cn { c_fp_exp_2_tl } + { { 7 } { 389056098 } { 930650227 } { 0 } } +\tl_new:c { c_fp_exp_3_tl } +\tl_set:cn { c_fp_exp_3_tl } + { { 2 } { 008553692 } { 318766774 } { 1 } } +\tl_new:c { c_fp_exp_4_tl } +\tl_set:cn { c_fp_exp_4_tl } + { { 5 } { 459815003 } { 314423908 } { 1 } } +\tl_new:c { c_fp_exp_5_tl } +\tl_set:cn { c_fp_exp_5_tl } + { { 1 } { 484131591 } { 025766034 } { 2 } } +\tl_new:c { c_fp_exp_6_tl } +\tl_set:cn { c_fp_exp_6_tl } + { { 4 } { 034287934 } { 927351226 } { 2 } } +\tl_new:c { c_fp_exp_7_tl } +\tl_set:cn { c_fp_exp_7_tl } + { { 1 } { 096633158 } { 428458599 } { 3 } } +\tl_new:c { c_fp_exp_8_tl } +\tl_set:cn { c_fp_exp_8_tl } + { { 2 } { 980957987 } { 041728275 } { 3 } } +\tl_new:c { c_fp_exp_9_tl } +\tl_set:cn { c_fp_exp_9_tl } + { { 8 } { 103083927 } { 575384008 } { 3 } } +\tl_new:c { c_fp_exp_10_tl } +\tl_set:cn { c_fp_exp_10_tl } + { { 2 } { 202646579 } { 480671652 } { 4 } } +\tl_new:c { c_fp_exp_20_tl } +\tl_set:cn { c_fp_exp_20_tl } + { { 4 } { 851651954 } { 097902280 } { 8 } } +\tl_new:c { c_fp_exp_30_tl } +\tl_set:cn { c_fp_exp_30_tl } + { { 1 } { 068647458 } { 152446215 } { 13 } } +\tl_new:c { c_fp_exp_40_tl } +\tl_set:cn { c_fp_exp_40_tl } + { { 2 } { 353852668 } { 370199854 } { 17 } } +\tl_new:c { c_fp_exp_50_tl } +\tl_set:cn { c_fp_exp_50_tl } + { { 5 } { 184705528 } { 587072464 } { 21 } } +\tl_new:c { c_fp_exp_60_tl } +\tl_set:cn { c_fp_exp_60_tl } + { { 1 } { 142007389 } { 815684284 } { 26 } } +\tl_new:c { c_fp_exp_70_tl } +\tl_set:cn { c_fp_exp_70_tl } + { { 2 } { 515438670 } { 919167006 } { 30 } } +\tl_new:c { c_fp_exp_80_tl } +\tl_set:cn { c_fp_exp_80_tl } + { { 5 } { 540622384 } { 393510053 } { 34 } } +\tl_new:c { c_fp_exp_90_tl } +\tl_set:cn { c_fp_exp_90_tl } + { { 1 } { 220403294 } { 317840802 } { 39 } } +\tl_new:c { c_fp_exp_100_tl } +\tl_set:cn { c_fp_exp_100_tl } + { { 2 } { 688117141 } { 816135448 } { 43 } } +\tl_new:c { c_fp_exp_200_tl } +\tl_set:cn { c_fp_exp_200_tl } + { { 7 } { 225973768 } { 125749258 } { 86 } } % \end{macrocode} %\end{macro} %\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} % -%\begin{macro}{\fp_if_zero_p:N} -%\begin{macro}[TF]{\fp_if_zero:N} -% Testing for a zero fixed-point is also easy. +%\begin{macro}{\c_fp_exp_-1_tl} +%\begin{macro}{\c_fp_exp_-2_tl} +%\begin{macro}{\c_fp_exp_-3_tl} +%\begin{macro}{\c_fp_exp_-4_tl} +%\begin{macro}{\c_fp_exp_-5_tl} +%\begin{macro}{\c_fp_exp_-6_tl} +%\begin{macro}{\c_fp_exp_-7_tl} +%\begin{macro}{\c_fp_exp_-8_tl} +%\begin{macro}{\c_fp_exp_-9_tl} +%\begin{macro}{\c_fp_exp_-10_tl} +%\begin{macro}{\c_fp_exp_-20_tl} +%\begin{macro}{\c_fp_exp_-30_tl} +%\begin{macro}{\c_fp_exp_-40_tl} +%\begin{macro}{\c_fp_exp_-50_tl} +%\begin{macro}{\c_fp_exp_-60_tl} +%\begin{macro}{\c_fp_exp_-70_tl} +%\begin{macro}{\c_fp_exp_-80_tl} +%\begin{macro}{\c_fp_exp_-90_tl} +%\begin{macro}{\c_fp_exp_-100_tl} +%\begin{macro}{\c_fp_exp_-200_tl} +% Now the negative integers. % \begin{macrocode} -\prg_new_conditional:Npnn \fp_if_zero:N #1 { p , T , F , TF } { - \tex_ifx:D #1 \c_zero_fp - \prg_return_true: - \tex_else:D - \prg_return_false: - \tex_fi:D -} +\tl_new:c { c_fp_exp_-1_tl } +\tl_set:cn { c_fp_exp_-1_tl } + { { 3 } { 678794411 } { 71442322 } { -1 } } +\tl_new:c { c_fp_exp_-2_tl } +\tl_set:cn { c_fp_exp_-2_tl } + { { 1 } { 353352832 } { 366132692 } { -1 } } +\tl_new:c { c_fp_exp_-3_tl } +\tl_set:cn { c_fp_exp_-3_tl } + { { 4 } { 978706836 } { 786394298 } { -2 } } +\tl_new:c { c_fp_exp_-4_tl } +\tl_set:cn { c_fp_exp_-4_tl } + { { 1 } { 831563888 } { 873418029 } { -2 } } +\tl_new:c { c_fp_exp_-5_tl } +\tl_set:cn { c_fp_exp_-5_tl } + { { 6 } { 737946999 } { 085467097 } { -3 } } +\tl_new:c { c_fp_exp_-6_tl } +\tl_set:cn { c_fp_exp_-6_tl } + { { 2 } { 478752176 } { 666358423 } { -3 } } +\tl_new:c { c_fp_exp_-7_tl } +\tl_set:cn { c_fp_exp_-7_tl } + { { 9 } { 118819655 } { 545162080 } { -4 } } +\tl_new:c { c_fp_exp_-8_tl } +\tl_set:cn { c_fp_exp_-8_tl } + { { 3 } { 354626279 } { 025118388 } { -4 } } +\tl_new:c { c_fp_exp_-9_tl } +\tl_set:cn { c_fp_exp_-9_tl } + { { 1 } { 234098040 } { 866795495 } { -4 } } +\tl_new:c { c_fp_exp_-10_tl } +\tl_set:cn { c_fp_exp_-10_tl } + { { 4 } { 539992976 } { 248451536 } { -5 } } +\tl_new:c { c_fp_exp_-20_tl } +\tl_set:cn { c_fp_exp_-20_tl } + { { 2 } { 061153622 } { 438557828 } { -9 } } +\tl_new:c { c_fp_exp_-30_tl } +\tl_set:cn { c_fp_exp_-30_tl } + { { 9 } { 357622968 } { 840174605 } { -14 } } +\tl_new:c { c_fp_exp_-40_tl } +\tl_set:cn { c_fp_exp_-40_tl } + { { 4 } { 248354255 } { 291588995 } { -18 } } +\tl_new:c { c_fp_exp_-50_tl } +\tl_set:cn { c_fp_exp_-50_tl } + { { 1 } { 928749847 } { 963917783 } { -22 } } +\tl_new:c { c_fp_exp_-60_tl } +\tl_set:cn { c_fp_exp_-60_tl } + { { 8 } { 756510762 } { 696520338 } { -27 } } +\tl_new:c { c_fp_exp_-70_tl } +\tl_set:cn { c_fp_exp_-70_tl } + { { 3 } { 975449735 } { 908646808 } { -31 } } +\tl_new:c { c_fp_exp_-80_tl } +\tl_set:cn { c_fp_exp_-80_tl } + { { 1 } { 804851387 } { 845415172 } { -35 } } +\tl_new:c { c_fp_exp_-90_tl } +\tl_set:cn { c_fp_exp_-90_tl } + { { 8 } { 194012623 } { 990515430 } { -40 } } +\tl_new:c { c_fp_exp_-100_tl } +\tl_set:cn { c_fp_exp_-100_tl } + { { 3 } { 720075976 } { 020835963 } { -44 } } +\tl_new:c { c_fp_exp_-200_tl } +\tl_set:cn { c_fp_exp_-200_tl } + { { 1 } { 383896526 } { 736737530 } { -87 } } % \end{macrocode} %\end{macro} %\end{macro} -% -%\subsection{Floating-point conditionals} -% -%\begin{macro}[TF]{\fp_compare:nNn} -%\begin{macro}[TF]{\fp_compare:NNN} -%\begin{macro}[aux]{\fp_compare_aux:N} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +% +%\begin{macro}{\fp_exp:Nn} +%\begin{macro}{\fp_exp:cn} +%\begin{macro}{\fp_gexp:Nn} +%\begin{macro}{\fp_gexp:cn} +%\begin{macro}[aux]{\fp_exp_aux:NNn} +%\begin{macro}[aux]{\fp_exp_internal:} +%\begin{macro}[aux]{\fp_exp_aux:} +%\begin{macro}[aux]{\fp_exp_integer:} +%\begin{macro}[aux]{\fp_exp_integer_tens:} +%\begin{macro}[aux]{\fp_exp_integer_units:} +%\begin{macro}[aux]{\fp_exp_integer_const:n} +%\begin{macro}[aux]{\fp_exp_integer_const:nnnn} +%\begin{macro}[aux]{\fp_exp_decimal:} +%\begin{macro}[aux]{\fp_exp_Taylor:} +%\begin{macro}[aux]{\fp_exp_const:Nx} +%\begin{macro}[aux]{\fp_exp_const:cx} +% The calculation of an exponent starts off starts in much the same +% way as the trigonometric functions: normalise the input, look for +% a pre-defined value and if one is not found hand off to the real +% workhorse function. The test for a definition of the result is used +% so that overflows do not result in any outcome being defined. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_exp:Nn { + \fp_exp_aux:NNn \tl_set:Nn +} +\cs_new_protected_nopar:Npn \fp_gexp:Nn { + \fp_exp_aux:NNn \tl_gset:Nn +} +\cs_generate_variant:Nn \fp_exp:Nn { c } +\cs_generate_variant:Nn \fp_gexp:Nn { c } +\cs_new_protected_nopar:Npn \fp_exp_aux:NNn #1#2#3 { + \group_begin: + \fp_split:Nn a {#3} + \fp_standardise:NNNN + \l_fp_input_a_sign_int + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + \l_fp_input_a_exponent_int + \l_fp_input_a_extended_int \c_zero + \tl_set:Nx \l_fp_arg_tl + { + \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero + - + \tex_else:D + + + \tex_fi:D + \int_use:N \l_fp_input_a_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_input_a_decimal_int + \c_one_thousand_million + e + \int_use:N \l_fp_input_a_exponent_int + } + \etex_ifcsname:D c_fp_exp ( \l_fp_arg_tl ) _fp \tex_endcsname:D + \tex_else:D + \tex_expandafter:D \fp_exp_internal: + \tex_fi:D + \cs_set_protected_nopar:Npx \fp_tmp:w + { + \group_end: + #1 \exp_not:N #2 + { + \etex_ifcsname:D c_fp_exp ( \l_fp_arg_tl ) _fp + \tex_endcsname:D + \use:c { c_fp_exp ( \l_fp_arg_tl ) _fp } + \tex_else:D + \c_zero_fp + \tex_fi:D + } + } + \fp_tmp:w +} +% \end{macrocode} +% The first real step is to convert the input into a fixed-point +% representation for further calculation: anything which is dropped +% here as too small would not influence the output in any case. There +% are a couple of overflow tests: the maximum +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_exp_internal: { + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_three + \fp_extended_normalise: + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \tex_ifnum:D \l_fp_input_a_integer_int < 230 \scan_stop: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_aux: + \tex_else:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_overflow_msg: + \tex_fi:D + \tex_else:D + \tex_ifnum:D \l_fp_input_a_integer_int < 230 \scan_stop: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_aux: + \tex_else:D + \fp_exp_const:cx { c_fp_exp ( \l_fp_arg_tl ) _fp } + { \c_zero_fp } + \tex_fi:D + \tex_fi:D + \tex_else:D + \tex_expandafter:D \fp_exp_overflow_msg: + \tex_fi:D +} +% \end{macrocode} +% The main algorithm makes use of the fact that +% \[ +% \mathrm{e}^{nmp.q} = +% \mathrm{e}^{n} +% \mathrm{e}^{m} +% \mathrm{e}^{p} +% \mathrm{e}^{0.q} +% \] +% and that there is a Taylor series that can be used to calculate +% \( \mathrm{e}^{0.q} \). Thus the approach needed is in three parts. +% First, the exponent of the integer part of the input is found +% using the pre-calculated constants. Second, the Taylor series is +% used to find the exponent for the decimal part of the input. Finally, +% the two parts are multiplied together to give the result. As the +% normalisation code will already have dealt with any overflowing +% values, there are no further checks needed. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_exp_aux: { + \tex_ifnum:D \l_fp_input_a_integer_int > \c_zero + \tex_expandafter:D \fp_exp_integer: + \tex_else:D + \l_fp_output_integer_int \c_one + \l_fp_output_decimal_int \c_zero + \l_fp_output_extended_int \c_zero + \l_fp_output_exponent_int \c_zero + \tex_expandafter:D \fp_exp_decimal: + \tex_fi:D +} +% \end{macrocode} +% The integer part calculation starts with the hundreds. This is +% set up such that very large negative numbers can short-cut the entire +% procedure and simply return zero. In other cases, the code either +% recovers the exponent of the hundreds value or sets the appropriate +% storage to one (so that multiplication works correctly). +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_exp_integer: { + \tex_ifnum:D \l_fp_input_a_integer_int < \c_one_hundred + \l_fp_exp_integer_int \c_one + \l_fp_exp_decimal_int \c_zero + \l_fp_exp_extended_int \c_zero + \l_fp_exp_exponent_int \c_zero + \tex_expandafter:D \fp_exp_integer_tens: + \tex_else:D + \tl_set:Nx \l_fp_tmp_tl + { + \tex_expandafter:D \use_i:nnn + \int_use:N \l_fp_input_a_integer_int + } + \l_fp_input_a_integer_int + \etex_numexpr:D + \l_fp_input_a_integer_int - \l_fp_tmp_tl 00 + \scan_stop: + \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero + \tex_ifnum:D \l_fp_output_integer_int > 200 \scan_stop: + \fp_exp_const:cx { c_fp_exp ( \l_fp_arg_tl ) _fp } + { \c_zero_fp } + \tex_else:D + \fp_exp_integer_const:n { - \l_fp_tmp_tl 00 } + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_integer_tens: + \tex_fi:D + \tex_else:D + \fp_exp_integer_const:n { \l_fp_tmp_tl 00 } + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_integer_tens: + \tex_fi:D + \tex_fi:D +} +% \end{macrocode} +% The tens and units parts are handled in a similar way, with a +% multiplication step to build up the final value. That also includes a +% correction step to avoid an overflow of the integer part. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_exp_integer_tens: { + \l_fp_output_integer_int \l_fp_exp_integer_int + \l_fp_output_decimal_int \l_fp_exp_decimal_int + \l_fp_output_extended_int \l_fp_exp_extended_int + \l_fp_output_exponent_int \l_fp_exp_exponent_int + \tex_ifnum:D \l_fp_input_a_integer_int > \c_nine + \tl_set:Nx \l_fp_tmp_tl + { + \tex_expandafter:D \use_i:nn + \int_use:N \l_fp_input_a_integer_int + } + \l_fp_input_a_integer_int + \etex_numexpr:D + \l_fp_input_a_integer_int - \l_fp_tmp_tl 0 + \scan_stop: + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \fp_exp_integer_const:n { \l_fp_tmp_tl 0 } + \tex_else:D + \fp_exp_integer_const:n { - \l_fp_tmp_tl 0 } + \tex_fi:D + \fp_mul:NNNNNNNNN + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_advance:D \l_fp_output_exponent_int \l_fp_exp_exponent_int + \fp_extended_normalise_output: + \tex_fi:D + \fp_exp_integer_units: +} +\cs_new_protected_nopar:Npn \fp_exp_integer_units: { + \tex_ifnum:D \l_fp_input_a_integer_int > \c_zero + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \fp_exp_integer_const:n { \int_use:N \l_fp_input_a_integer_int } + \tex_else:D + \fp_exp_integer_const:n + { - \int_use:N \l_fp_input_a_integer_int } + \tex_fi:D + \fp_mul:NNNNNNNNN + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_advance:D \l_fp_output_exponent_int \l_fp_exp_exponent_int + \fp_extended_normalise_output: + \tex_fi:D + \fp_exp_decimal: +} +% \end{macrocode} +% Recovery of the stored constant values into the separate registers +% is done with a simple expansion then assignment. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_exp_integer_const:n #1 { + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_exp_integer_const:nnnn + \tex_csname:D c_fp_exp_ #1 _tl \tex_endcsname:D +} +\cs_new_protected_nopar:Npn \fp_exp_integer_const:nnnn #1#2#3#4 { + \l_fp_exp_integer_int #1 \scan_stop: + \l_fp_exp_decimal_int #2 \scan_stop: + \l_fp_exp_extended_int #3 \scan_stop: + \l_fp_exp_exponent_int #4 \scan_stop: +} +% \end{macrocode} +% Finding the exponential for the decimal part of the number requires +% a Taylor series calculation. The set up is done here with the loop +% itself a separate function. Once the decimal part is available this +% is multiplied by the integer part already worked out to give +% the final result. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_exp_decimal: { + \tex_ifnum:D \l_fp_input_a_decimal_int > \c_zero + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \l_fp_exp_integer_int \c_one + \l_fp_exp_decimal_int \l_fp_input_a_decimal_int + \l_fp_exp_extended_int \l_fp_input_a_extended_int + \tex_else:D + \l_fp_exp_integer_int \c_zero + \tex_ifnum:D \l_fp_exp_extended_int = \c_zero + \l_fp_exp_decimal_int + \etex_numexpr:D + \c_one_thousand_million - \l_fp_input_a_decimal_int + \scan_stop: + \l_fp_exp_extended_int \c_zero + \tex_else:D + \l_fp_exp_decimal_int + \etex_numexpr:D + 999999999 - \l_fp_input_a_decimal_int + \scan_stop: + \l_fp_exp_extended_int + \etex_numexpr:D + \c_one_thousand_million - \l_fp_input_a_extended_int + \scan_stop: + \tex_fi:D + \tex_fi:D + \l_fp_input_b_sign_int \l_fp_input_a_sign_int + \l_fp_input_b_decimal_int \l_fp_input_a_decimal_int + \l_fp_input_b_extended_int \l_fp_input_a_extended_int + \l_fp_count_int \c_one + \fp_exp_Taylor: + \fp_mul:NNNNNNNNN + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_fi:D + \tex_ifnum:D \l_fp_output_extended_int < \c_five_hundred_million + \tex_else:D + \tex_advance:D \l_fp_output_decimal_int \c_one + \tex_ifnum:D \l_fp_output_decimal_int < \c_one_thousand_million + \tex_else:D + \l_fp_output_decimal_int \c_zero + \tex_advance:D \l_fp_output_integer_int \c_one + \tex_fi:D + \tex_fi:D + \fp_standardise:NNNN + \l_fp_output_sign_int + \l_fp_output_integer_int + \l_fp_output_decimal_int + \l_fp_output_exponent_int + \fp_exp_const:cx { c_fp_exp ( \l_fp_arg_tl ) _fp } + { + + + \int_use:N \l_fp_output_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_output_decimal_int + \c_one_thousand_million + \scan_stop: + e + \int_use:N \l_fp_output_exponent_int + } +} +% \end{macrocode} +% The Taylor series for \( \exp(x) \) is +%\[ +% 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \cdots +%\] +% which converges for \( -1 < x < 1 \). The code above sets up +% the \( x \) part, leaving the loop to multiply the running +% value by \( x / n \) and add it onto the sum. The way that this is +% done is that the running total is stored in the \texttt{exp} set of +% registers, while the current item is stored as \texttt{input_b}. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_exp_Taylor: { + \tex_advance:D \l_fp_count_int \c_one + \tex_multiply:D \l_fp_input_b_sign_int \l_fp_input_a_sign_int + \fp_mul:NNNNNN + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \fp_div_integer:NNNNN + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \l_fp_count_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_b_decimal_int + \l_fp_input_b_extended_int + > \c_zero + \tex_ifnum:D \l_fp_input_b_sign_int > \c_zero + \tex_advance:D \l_fp_exp_decimal_int \l_fp_input_b_decimal_int + \tex_advance:D \l_fp_exp_extended_int + \l_fp_input_b_extended_int + \tex_ifnum:D \l_fp_exp_extended_int < \c_one_thousand_million + \tex_else:D + \tex_advance:D \l_fp_exp_decimal_int \c_one + \tex_advance:D \l_fp_exp_extended_int + -\c_one_thousand_million + \tex_fi:D + \tex_ifnum:D \l_fp_exp_decimal_int < \c_one_thousand_million + \tex_else:D + \tex_advance:D \l_fp_exp_integer_int \c_one + \tex_advance:D \l_fp_exp_decimal_int + -\c_one_thousand_million + \tex_fi:D + \tex_else:D + \tex_advance:D \l_fp_exp_decimal_int -\l_fp_input_b_decimal_int + \tex_advance:D \l_fp_exp_extended_int + -\l_fp_input_a_extended_int + \tex_ifnum:D \l_fp_exp_extended_int < \c_zero + \tex_advance:D \l_fp_exp_decimal_int \c_minus_one + \tex_advance:D \l_fp_exp_extended_int \c_one_thousand_million + \tex_fi:D + \tex_ifnum:D \l_fp_exp_decimal_int < \c_zero + \tex_advance:D \l_fp_exp_integer_int \c_minus_one + \tex_advance:D \l_fp_exp_decimal_int \c_one_thousand_million + \tex_fi:D + \tex_fi:D + \tex_expandafter:D \fp_exp_Taylor: + \tex_fi:D +} +% \end{macrocode} +% This is set up as a function so that the power code can redirect +% the effect. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_exp_const:Nx #1#2 { + \tl_new:N #1 + \tl_gset:Nx #1 {#2} +} +\cs_generate_variant:Nn \fp_exp_const:Nx { c } +% \end{macrocode} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +% +%\begin{macro}{\c_fp_ln_10_1_tl} +%\begin{macro}{\c_fp_ln_10_2_tl} +%\begin{macro}{\c_fp_ln_10_3_tl} +%\begin{macro}{\c_fp_ln_10_4_tl} +%\begin{macro}{\c_fp_ln_10_5_tl} +%\begin{macro}{\c_fp_ln_10_6_tl} +%\begin{macro}{\c_fp_ln_10_7_tl} +%\begin{macro}{\c_fp_ln_10_8_tl} +%\begin{macro}{\c_fp_ln_10_9_tl} +% Constants for working out logarithms: first those for the powers of +% ten. +% \begin{macrocode} +\tl_new:c { c_fp_ln_10_1_tl } +\tl_set:cn { c_fp_ln_10_1_tl } + { { 2 } { 302585092 } { 994045684 } { 0 } } +\tl_new:c { c_fp_ln_10_2_tl } +\tl_set:cn { c_fp_ln_10_2_tl } + { { 4 } { 605170185 } { 988091368 } { 0 } } +\tl_new:c { c_fp_ln_10_3_tl } +\tl_set:cn { c_fp_ln_10_3_tl } + { { 6 } { 907755278 } { 982137052 } { 0 } } +\tl_new:c { c_fp_ln_10_4_tl } +\tl_set:cn { c_fp_ln_10_4_tl } + { { 9 } { 210340371 } { 976182736 } { 0 } } +\tl_new:c { c_fp_ln_10_5_tl } +\tl_set:cn { c_fp_ln_10_5_tl } + { { 1 } { 151292546 } { 497022842 } { 1 } } +\tl_new:c { c_fp_ln_10_6_tl } +\tl_set:cn { c_fp_ln_10_6_tl } + { { 1 } { 381551055 } { 796427410 } { 1 } } +\tl_new:c { c_fp_ln_10_7_tl } +\tl_set:cn { c_fp_ln_10_7_tl } + { { 1 } { 611809565 } { 095831979 } { 1 } } +\tl_new:c { c_fp_ln_10_8_tl } +\tl_set:cn { c_fp_ln_10_8_tl } + { { 1 } { 842068074 } { 395226547 } { 1 } } +\tl_new:c { c_fp_ln_10_9_tl } +\tl_set:cn { c_fp_ln_10_9_tl } + { { 2 } { 072326583 } { 694641116 } { 1 } } +% \end{macrocode} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +% +%\begin{macro}{\c_fp_ln_2_1_tl } +%\begin{macro}{\c_fp_ln_2_2_tl } +%\begin{macro}{\c_fp_ln_2_3_tl } +% The smaller set for powers of two. +% \begin{macrocode} +\tl_new:c { c_fp_ln_2_1_tl } +\tl_set:cn { c_fp_ln_2_1_tl } + { { 0 } { 693147180 } { 559945309 } { 0 } } +\tl_new:c { c_fp_ln_2_2_tl } +\tl_set:cn { c_fp_ln_2_2_tl } + { { 1 } { 386294361 } { 119890618 } { 0 } } +\tl_new:c { c_fp_ln_2_3_tl } +\tl_set:cn { c_fp_ln_2_3_tl } + { { 2 } { 079441541 } { 679835928 } { 0 } } +% \end{macrocode} +%\end{macro} +%\end{macro} +%\end{macro} +% +%\begin{macro}{\fp_ln:Nn} +%\begin{macro}{\fp_ln:cn} +%\begin{macro}{\fp_gln:Nn} +%\begin{macro}{\fp_gln:cn} +%\begin{macro}[aux]{\fp_ln_aux:NNn} +%\begin{macro}[aux]{\fp_ln_aux:} +%\begin{macro}[aux]{\fp_ln_exponent:} +%\begin{macro}[aux]{\fp_ln_internal:} +%\begin{macro}[aux]{\fp_ln_exponent_units:} +%\begin{macro}[aux]{\fp_ln_normalise:} +%\begin{macro}[aux]{\fp_ln_nornalise_aux:NNNNNNNNN} +%\begin{macro}[aux]{\fp_ln_mantissa:} +%\begin{macro}[aux]{\fp_ln_mantissa_aux:} +%\begin{macro}[aux]{\fp_ln_mantissa_divide_two:} +%\begin{macro}[aux]{\fp_ln_integer_const:nn} +%\begin{macro}[aux]{\fp_ln_Taylor:} +%\begin{macro}[aux]{\fp_ln_fixed:} +%\begin{macro}[aux]{\fp_ln_fixed_aux:NNNNNNNNN} +%\begin{macro}[aux]{\fp_ln_Taylor_aux:} +% The approach for logarithms is again based on a mix of tables and +% Taylor series. Here, the initial validation is a bit easier and so it +% is set up earlier, meaning less need to escape later on. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln:Nn { + \fp_ln_aux:NNn \tl_set:Nn +} +\cs_new_protected_nopar:Npn \fp_gln:Nn { + \fp_ln_aux:NNn \tl_gset:Nn +} +\cs_generate_variant:Nn \fp_ln:Nn { c } +\cs_generate_variant:Nn \fp_gln:Nn { c } +\cs_new_protected_nopar:Npn \fp_ln_aux:NNn #1#2#3 { + \group_begin: + \fp_split:Nn a {#3} + \fp_standardise:NNNN + \l_fp_input_a_sign_int + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + \l_fp_input_a_exponent_int + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + > \c_zero + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_ln_aux: + \tex_else:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 \exp_not:N ##2 { \c_zero_fp } + } + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_ln_error_msg: + \tex_fi:D + \tex_else:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 \exp_not:N ##2 { \c_zero_fp } + } + \tex_expandafter:D \fp_ln_error_msg: + \tex_fi:D + \fp_tmp:w #1 #2 +} +% \end{macrocode} +% As the input at this stage meets the validity criteria above, the +% argument can now be saved for further processing. There is no need +% to look at the sign of the input as it must be positive. The function +% here simply sets up to either do the full calculation or recover +% the stored value, as appropriate. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_aux: { + \tl_set:Nx \l_fp_arg_tl + { + + + \int_use:N \l_fp_input_a_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_input_a_decimal_int + \c_one_thousand_million + e + \int_use:N \l_fp_input_a_exponent_int + } + \etex_ifcsname:D c_fp_ln ( \l_fp_arg_tl ) _fp \tex_endcsname:D + \tex_else:D + \tex_expandafter:D \fp_ln_exponent: + \tex_fi:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 \exp_not:N ##2 + { \use:c { c_fp_ln ( \l_fp_arg_tl ) _fp } } + } +} +% \end{macrocode} +% The main algorithm here uses the fact the logarithm can be divided +% up, first taking out the powers of ten, then powers of two and finally +% using a Taylor series for the remainder. +%\[ +% \ln ( 10^{n} \times 2^{m} \times x ) +% = \ln ( 10^{n} ) \times \ln ( 2^{m} ) \times \ln ( x ) +%\] +% The second point to remember is that +%\[ +% \ln ( x^{-1} ) = - \ln ( x ) +%\] +% which means that for the powers of \( 10 \) and \( 2 \) constants +% are only needed for positive powers. +% +% The first step is to set up the sign for the output functions and +% work out the powers of ten in the exponent. First the larger powers +% are sorted out. The values for the constants are the same as those +% for the smaller ones, just with a shift in the exponent. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_exponent: { + \fp_ln_internal: + \tex_ifnum:D \l_fp_output_extended_int < \c_five_hundred_million + \tex_else:D + \tex_advance:D \l_fp_output_decimal_int \c_one + \tex_ifnum:D \l_fp_output_decimal_int < \c_one_thousand_million + \tex_else:D + \l_fp_output_decimal_int \c_zero + \tex_advance:D \l_fp_output_integer_int \c_one + \tex_fi:D + \tex_fi:D + \fp_standardise:NNNN + \l_fp_output_sign_int + \l_fp_output_integer_int + \l_fp_output_decimal_int + \l_fp_output_exponent_int + \tl_new:c { c_fp_ln ( \l_fp_arg_tl ) _fp } + \tl_gset:cx { c_fp_ln ( \l_fp_arg_tl ) _fp } + { + \tex_ifnum:D \l_fp_output_sign_int > \c_zero + + + \tex_else:D + - + \tex_fi:D + \int_use:N \l_fp_output_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_output_decimal_int + \c_one_thousand_million + \scan_stop: + e + \int_use:N \l_fp_output_exponent_int + } +} +\cs_new_protected_nopar:Npn \fp_ln_internal: { + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_zero + \l_fp_input_a_exponent_int -\l_fp_input_a_exponent_int + \l_fp_output_sign_int \c_minus_one + \tex_else:D + \l_fp_output_sign_int \c_one + \tex_fi:D + \tex_ifnum:D \l_fp_input_a_exponent_int > \c_nine + \tl_set:Nx \l_fp_tmp_tl + { + \tex_expandafter:D \use_i:nn + \int_use:N \l_fp_input_a_exponent_int + } + \l_fp_input_a_exponent_int + \etex_numexpr:D + \l_fp_input_a_exponent_int - \l_fp_tmp_tl 0 + \scan_stop: + \fp_ln_const:nn { 10 } { \l_fp_tmp_tl } + \tex_advance:D \l_fp_exp_exponent_int \c_one + \l_fp_output_integer_int \l_fp_exp_integer_int + \l_fp_output_decimal_int \l_fp_exp_decimal_int + \l_fp_output_extended_int \l_fp_exp_extended_int + \l_fp_output_exponent_int \l_fp_exp_exponent_int + \tex_else:D + \l_fp_output_integer_int \c_zero + \l_fp_output_decimal_int \c_zero + \l_fp_output_extended_int \c_zero + \l_fp_output_exponent_int \c_zero + \tex_fi:D + \fp_ln_exponent_units: +} +% \end{macrocode} +% Next the smaller powers of ten, which will need to be combined +% with the above: always an additive process. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_exponent_units: { + \tex_ifnum:D \l_fp_input_a_exponent_int > \c_zero + \fp_ln_const:nn { 10 } { \int_use:N \l_fp_input_a_exponent_int } + \fp_ln_normalise: + \fp_add:NNNNNNNNN + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_fi:D + \fp_ln_mantissa: +} +% \end{macrocode} +% The smaller table-based parts may need to be exponent shifted so that +% they stay in line with the larger parts. This is similar to the +% approach in other places, but here there is a need to watch the +% extended part of the number. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_normalise: { + \tex_ifnum:D \l_fp_exp_exponent_int < \l_fp_output_exponent_int + \tex_advance:D \l_fp_exp_decimal_int \c_one_thousand_million + \tex_expandafter:D \use_i:nn \tex_expandafter:D + \fp_ln_normalise_aux:NNNNNNNNN + \int_use:N \l_fp_exp_decimal_int + \tex_expandafter:D \fp_ln_normalise: + \tex_fi:D +} +\cs_new_protected_nopar:Npn + \fp_ln_normalise_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \tex_ifnum:D \l_fp_exp_integer_int = \c_zero + \l_fp_exp_decimal_int #1#2#3#4#5#6#7#8 \scan_stop: + \tex_else:D + \tl_set:Nx \l_fp_tmp_tl + { + \int_use:N \l_fp_exp_integer_int + #1#2#3#4#5#6#7#8 + } + \l_fp_exp_integer_int \c_zero + \l_fp_exp_decimal_int \l_fp_tmp_tl \scan_stop: + \tex_fi:D + \tex_divide:D \l_fp_exp_extended_int \c_ten + \tl_set:Nx \l_fp_tmp_tl + { + #9 + \int_use:N \l_fp_exp_extended_int + } + \l_fp_exp_extended_int \l_fp_tmp_tl \scan_stop: + \tex_advance:D \l_fp_exp_exponent_int \c_one +} +% \end{macrocode} +% The next phase is to decompose the mantissa by division by two to +% leave a value which is in the range \( 1 \le x < 2 \). The sum of the +% two powers needs to take account of the sign of the output: if it +% is negative then the result gets \emph{smaller} as the mantissa gets +% \emph{bigger}. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_mantissa: { + \l_fp_count_int \c_zero + \l_fp_input_a_extended_int \c_zero + \fp_ln_mantissa_aux: + \tex_ifnum:D \l_fp_count_int > \c_zero + \fp_ln_const:nn { 2 } { \int_use:N \l_fp_count_int } + \fp_ln_normalise: + \tex_ifnum:D \l_fp_output_sign_int > \c_zero + \tex_expandafter:D \fp_add:NNNNNNNNN + \tex_else:D + \tex_expandafter:D \fp_sub:NNNNNNNNN + \tex_fi:D + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_fi:D + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int > \c_one + \scan_stop: + \tex_expandafter:D \fp_ln_Taylor: + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_ln_mantissa_aux: { + \tex_ifnum:D \l_fp_input_a_integer_int > \c_one + \tex_advance:D \l_fp_count_int \c_one + \fp_ln_mantissa_divide_two: + \tex_expandafter:D \fp_ln_mantissa_aux: + \tex_fi:D +} +% \end{macrocode} +% A fast one-shot division by two. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_mantissa_divide_two: { + \tex_ifodd:D \l_fp_input_a_decimal_int + \tex_advance:D \l_fp_input_a_extended_int \c_one_thousand_million + \tex_fi:D + \tex_ifodd:D \l_fp_input_a_integer_int + \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million + \tex_fi:D + \tex_divide:D \l_fp_input_a_integer_int \c_two + \tex_divide:D \l_fp_input_a_decimal_int \c_two + \tex_divide:D \l_fp_input_a_extended_int \c_two +} +% \end{macrocode} +% Recovering constants makes use of the same auxiliary code as for +% exponents. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_const:nn #1#2 { + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_exp_integer_const:nnnn + \tex_csname:D c_fp_ln_ #1 _ #2 _tl \tex_endcsname:D +} +% \end{macrocode} +% The Taylor series for the logarithm function is best implemented using +% the identity +%\[ +% \ln(x) = \ln\left( \frac{y + 1}{y - 1} \right) +%\] +% with +%\[ +% y = \frac{x - 1}{x + 1} +%\] +% This leads to the series +%\[ +% \ln(x) +% = 2y +% \left( +% 1 + y^{2} +% \left( +% \frac{1}{3} + y^{2} +% \left( +% \frac{1}{5} + y^{2} +% \left( +% \frac{1}{7} + y^{2} +% \left( +% \frac{1}{9} + \cdots +% \right) +% \right) +% \right) +% \right) +% \right) +%\] +% This expansion has the advantage that a lot of the work can be +% loaded up early by finding \( y^{2} \) before the loop itself starts. +% (In practice, the implementation does the multiplication by two at the +% end of the loop, and expands out the brackets as this is an overall +% more efficient approach.) +% +% At the implementation level, the code starts by calculating \( y \) +% and storing that in input \texttt{a} (which is no longer needed +% for other purposes). That is done using the full division system +% avoiding the parsing step. The value is then switched to a fixed-point +% representation. There is then some shuffling to get all of the working +% space set up. At this stage, a lot of registers are in use and so +% the Taylor series is calculated within a group so that the +% \texttt{output} variables can be used to hold the result. The value +% of \( y^{2} \) is held in input \texttt{b} (there are a few +% assignments saved by choosing this over \texttt{a}), while input +% \texttt{a} is used for the `loop value'. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_Taylor: { + \group_begin: + \l_fp_input_a_integer_int \c_zero + \l_fp_input_a_exponent_int \c_zero + \l_fp_input_b_integer_int \c_two + \l_fp_input_b_decimal_int \l_fp_input_a_decimal_int + \l_fp_input_b_exponent_int \c_zero + \fp_div_internal: + \fp_ln_fixed: + \l_fp_input_a_integer_int \l_fp_output_integer_int + \l_fp_input_a_decimal_int \l_fp_output_decimal_int + \l_fp_input_a_exponent_int \l_fp_output_exponent_int + \l_fp_input_a_extended_int \c_zero + \l_fp_output_decimal_int \c_zero + \l_fp_output_decimal_int \l_fp_input_a_decimal_int + \l_fp_output_extended_int \l_fp_input_a_extended_int + \fp_mul:NNNNNN + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \l_fp_count_int \c_one + \fp_ln_Taylor_aux: + \cs_set_protected_nopar:Npx \fp_tmp:w + { + \group_end: + \exp_not:N \l_fp_exp_decimal_int + \int_use:N \l_fp_output_decimal_int \scan_stop: + \exp_not:N \l_fp_exp_extended_int + \int_use:N \l_fp_output_extended_int \scan_stop: + \exp_not:N \l_fp_exp_exponent_int + \int_use:N \l_fp_output_exponent_int \scan_stop: + } + \fp_tmp:w +% \end{macrocode} +% After the loop part of the Taylor series, the factor of \( 2 \) needs +% to be included. The total for the result can then be constructed. +% \begin{macrocode} + \tex_advance:D \l_fp_exp_decimal_int \l_fp_exp_decimal_int + \tex_ifnum:D \l_fp_exp_extended_int < \c_five_hundred_million + \tex_else:D + \tex_advance:D \l_fp_exp_extended_int -\c_five_hundred_million + \tex_advance:D \l_fp_exp_decimal_int \c_one + \tex_fi:D + \tex_advance:D \l_fp_exp_extended_int \l_fp_exp_extended_int + \tex_ifnum:D \l_fp_output_sign_int > \c_zero + \tex_expandafter:D \fp_add:NNNNNNNNN + \tex_else:D + \tex_expandafter:D \fp_sub:NNNNNNNNN + \tex_fi:D + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \c_zero \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int +} +% \end{macrocode} +% The usual shifts to move to fixed-point working. This is done using +% the \texttt{output} registers as this saves a reassignment here. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_fixed: { + \tex_ifnum:D \l_fp_output_exponent_int < \c_zero + \tex_advance:D \l_fp_output_decimal_int \c_one_thousand_million + \tex_expandafter:D \use_i:nn \tex_expandafter:D + \fp_ln_fixed_aux:NNNNNNNNN + \int_use:N \l_fp_output_decimal_int + \tex_expandafter:D \fp_ln_fixed: + \tex_fi:D +} +\cs_new_protected_nopar:Npn + \fp_ln_fixed_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \tex_ifnum:D \l_fp_output_integer_int = \c_zero + \l_fp_output_decimal_int #1#2#3#4#5#6#7#8 \scan_stop: + \tex_else:D + \tl_set:Nx \l_fp_tmp_tl + { + \int_use:N \l_fp_output_integer_int + #1#2#3#4#5#6#7#8 + } + \l_fp_output_integer_int \c_zero + \l_fp_output_decimal_int \l_fp_tmp_tl \scan_stop: + \tex_fi:D + \tex_advance:D \l_fp_output_exponent_int \c_one +} +% \end{macrocode} +% The main loop for the Taylor series: unlike some of the other similar +% functions, the result here is not the final value and is therefore +% subject to further manipulation outside of the loop. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_ln_Taylor_aux: { + \tex_advance:D \l_fp_count_int \c_two + \fp_mul:NNNNNN + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int + > \c_zero + \fp_div_integer:NNNNN + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_count_int + \l_fp_exp_decimal_int \l_fp_exp_extended_int + \tex_advance:D \l_fp_output_decimal_int \l_fp_exp_decimal_int + \tex_advance:D \l_fp_output_extended_int \l_fp_exp_extended_int + \tex_ifnum:D \l_fp_output_extended_int < \c_one_thousand_million + \tex_else:D + \tex_advance:D \l_fp_output_decimal_int \c_one + \tex_advance:D \l_fp_output_extended_int + -\c_one_thousand_million + \tex_fi:D + \tex_ifnum:D \l_fp_output_decimal_int < \c_one_thousand_million + \tex_else:D + \tex_advance:D \l_fp_output_integer_int \c_one + \tex_advance:D \l_fp_output_decimal_int + -\c_one_thousand_million + \tex_fi:D + \tex_expandafter:D \fp_ln_Taylor_aux: + \tex_fi:D +} +% \end{macrocode} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +% +%\begin{macro}{\fp_pow:Nn} +%\begin{macro}{\fp_pow:cn} +%\begin{macro}{\fp_gpow:Nn} +%\begin{macro}{\fp_gpow:cn} +%\begin{macro}[aux]{\fp_pow_aux:NNn} +%\begin{macro}[aux]{\fp_pow_aux_i:} +%\begin{macro}[aux]{\fp_pow_positive:} +%\begin{macro}[aux]{\fp_pow_negative:} +%\begin{macro}[aux]{\fp_pow_aux_ii:} +%\begin{macro}[aux]{\fp_pow_aux_iii:} +%\begin{macro}[aux]{\fp_pow_aux_iv:} +% The approach used for working out powers is to first filter out the +% various special cases and then do most of the work using the +% logarithm and exponent functions. The two storage areas are used +% in the reverse of the `natural' logic as this avoids some +% re-assignment in the sanity checking code. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_pow:Nn { + \fp_pow_aux:NNn \tl_set:Nn +} +\cs_new_protected_nopar:Npn \fp_gpow:Nn { + \fp_pow_aux:NNn \tl_gset:Nn +} +\cs_generate_variant:Nn \fp_pow:Nn { c } +\cs_generate_variant:Nn \fp_gpow:Nn { c } +\cs_new_protected_nopar:Npn \fp_pow_aux:NNn #1#2#3 { + \group_begin: + \fp_read:N #2 + \l_fp_input_b_sign_int \l_fp_input_a_sign_int + \l_fp_input_b_integer_int \l_fp_input_a_integer_int + \l_fp_input_b_decimal_int \l_fp_input_a_decimal_int + \l_fp_input_b_exponent_int \l_fp_input_a_exponent_int + \fp_split:Nn a {#3} + \fp_standardise:NNNN + \l_fp_input_a_sign_int + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + \l_fp_input_a_exponent_int + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int + = \c_zero + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + = \c_zero + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_undefined_fp } + } + \tex_else:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_zero_fp } + } + \tex_fi:D + \tex_else:D + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + = \c_zero + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_one_fp } + } + \tex_else:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_pow_aux_i: + \tex_fi:D + \tex_fi:D + \fp_tmp:w #1 #2 +} +% \end{macrocode} +% Simply using the logarithm function directly will fail when negative +% numbers are raised to integer powers, which is a mathematically valid +% operation. So there are some more tests to make, after forcing the +% power into an integer and decimal parts, if necessary. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_pow_aux_i: { + \tex_ifnum:D \l_fp_input_b_sign_int > \c_zero + \tl_set:Nn \l_fp_sign_tl { + } + \tex_expandafter:D \fp_pow_aux_ii: + \tex_else:D + \l_fp_input_a_extended_int \c_zero + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten + \group_begin: + \fp_extended_normalise: + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int + = \c_zero + \group_end: + \tl_set:Nn \l_fp_sign_tl { - } + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_pow_aux_ii: + \tex_else:D + \group_end: + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_undefined_fp } + } + \tex_fi:D + \tex_else:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_undefined_fp } + } + \tex_fi:D + \tex_fi:D +} +% \end{macrocode} +% The approach used here for powers works well in most cases but gives +% poorer results for negative integer powers, which often have exact +% values. So there is some filtering to do. For negative powers where +% the power is small, an alternative approach is used in which the +% positive value is worked out and the reciprocal is then taken. The +% filtering is unfortunately rather long. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_pow_aux_ii: { + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \tex_expandafter:D \fp_pow_aux_iv: + \tex_else:D + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten + \group_begin: + \l_fp_input_a_extended_int \c_zero + \fp_extended_normalise: + \tex_ifnum:D \l_fp_input_a_decimal_int = \c_zero + \tex_ifnum:D \l_fp_input_a_integer_int > \c_ten + \group_end: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_pow_aux_iv: + \tex_else:D + \group_end: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_pow_aux_iii: + \tex_fi:D + \tex_else:D + \group_end: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_pow_aux_iv: + \tex_fi:D + \tex_else:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_pow_aux_iv: + \tex_fi:D + \tex_fi:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 + { + \l_fp_sign_tl + \int_use:N \l_fp_output_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_output_decimal_int + \c_one_thousand_million + \scan_stop: + e + \int_use:N \l_fp_output_exponent_int + } + } +} +% \end{macrocode} +% For the small negative integer powers, the calculation is done for +% the positive power and the reciprocal is then taken. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_pow_aux_iii: { + \l_fp_input_a_sign_int \c_one + \fp_pow_aux_iv: + \l_fp_input_a_integer_int \c_one + \l_fp_input_a_decimal_int \c_zero + \l_fp_input_a_exponent_int \c_zero + \l_fp_input_b_integer_int \l_fp_output_integer_int + \l_fp_input_b_decimal_int \l_fp_output_decimal_int + \l_fp_input_b_exponent_int \l_fp_output_exponent_int + \fp_div_internal: +} +% \end{macrocode} +% The business end of the code starts by finding the logarithm of the +% given base. There is a bit of a shuffle so that this does not have +% to be re-parsed and so that the output ends up in the correct place. +% There is also a need to enable using the short-cut for a +% pre-calculated result. The internal part of the multiplication +% function can then be used to do the second part of the calculation +% directly. There is some more set up before doing the exponential: +% the idea here is to deactivate some internals so that everything works +% smoothly. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \fp_pow_aux_iv: { + \group_begin: + \l_fp_input_a_integer_int \l_fp_input_b_integer_int + \l_fp_input_a_decimal_int \l_fp_input_b_decimal_int + \l_fp_input_a_exponent_int \l_fp_input_b_exponent_int + \fp_ln_internal: + \cs_set_protected_nopar:Npx \fp_tmp:w + { + \group_end: + \exp_not:N \l_fp_input_b_sign_int + \int_use:N \l_fp_output_sign_int \scan_stop: + \exp_not:N \l_fp_input_b_integer_int + \int_use:N \l_fp_output_integer_int \scan_stop: + \exp_not:N \l_fp_input_b_decimal_int + \int_use:N \l_fp_output_decimal_int \scan_stop: + \exp_not:N \l_fp_input_b_extended_int + \int_use:N \l_fp_output_extended_int \scan_stop: + \exp_not:N \l_fp_input_b_exponent_int + \int_use:N \l_fp_output_exponent_int \scan_stop: + } + \fp_tmp:w + \l_fp_input_a_extended_int \c_zero + \fp_mul:NNNNNNNNN + \l_fp_input_a_integer_int \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int + \l_fp_input_b_integer_int \l_fp_input_b_decimal_int + \l_fp_input_b_extended_int + \l_fp_input_a_integer_int \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int + \tex_advance:D \l_fp_input_a_exponent_int \l_fp_input_b_exponent_int + \l_fp_output_integer_int \c_zero + \l_fp_output_decimal_int \c_zero + \l_fp_output_exponent_int \c_zero + \cs_set_eq:NN \fp_exp_const:Nx \use_none:nn + \fp_exp_internal: +} +% \end{macrocode} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +%\end{macro} +% +%\subsection{Tests for special values} +% +%\begin{macro}{\fp_if_undefined_p:N} +%\begin{macro}[TF]{\fp_if_undefined:N} +% Testing for an undefined value is easy. +% \begin{macrocode} +\prg_new_conditional:Npnn \fp_if_undefined:N #1 { T , F , TF , p } { + \tex_ifx:D #1 \c_undefined_fp + \prg_return_true: + \tex_else:D + \prg_return_false: + \tex_fi:D +} +% \end{macrocode} +%\end{macro} +%\end{macro} +% +%\begin{macro}{\fp_if_zero_p:N} +%\begin{macro}[TF]{\fp_if_zero:N} +% Testing for a zero fixed-point is also easy. +% \begin{macrocode} +\prg_new_conditional:Npnn \fp_if_zero:N #1 { T , F , TF , p } { + \tex_ifx:D #1 \c_zero_fp + \prg_return_true: + \tex_else:D + \prg_return_false: + \tex_fi:D +} +% \end{macrocode} +%\end{macro} +%\end{macro} +% +%\subsection{Floating-point conditionals} +% +%\begin{macro}[TF]{\fp_compare:nNn} +%\begin{macro}[TF]{\fp_compare:NNN} +%\begin{macro}[aux]{\fp_compare_aux:N} %\begin{macro}[aux]{\fp_compare_=:} %\begin{macro}[aux]{\fp_compare_<:} %\begin{macro}[aux]{\fp_compare_<_aux:} @@ -3777,7 +5495,8 @@ % faster. The lead off for both is the same: get the two numbers % read and then look for a function to handle the comparison. % \begin{macrocode} -\prg_new_protected_conditional:Npnn \fp_compare:nNn #1#2#3 { T , F , TF } +\prg_new_protected_conditional:Npnn \fp_compare:nNn #1#2#3 + { T , F , TF } { \group_begin: \fp_split:Nn a {#1} @@ -3794,7 +5513,8 @@ \l_fp_input_b_exponent_int \fp_compare_aux:N #2 } -\prg_new_protected_conditional:Npnn \fp_compare:NNN #1#2#3 { T , F , TF } +\prg_new_protected_conditional:Npnn \fp_compare:NNN #1#2#3 + { T , F , TF } { \group_begin: \fp_read:N #3 @@ -4026,6 +5746,33 @@ % \end{macrocode} %\end{macro} % +%\begin{macro}{\fp_exp_overflow_msg:} +% A slightly more helpful message for exponent overflows. +% \begin{macrocode} +\msg_kernel_new:nnnn { fpu } { exponent-overflow } + { Number~too~big~for~exponent~unit. } + { + The~exponent~of~the~input~given~is~too~big~for~the~floating~point~ + unit:~the~maximum~input~value~for~an~exponent~is~230. + } +\cs_new_protected_nopar:Npn \fp_exp_overflow_msg: { + \msg_kernel_error:nn { fpu } { exponent-overflow } +} +% \end{macrocode} +%\end{macro} +% +%\begin{macro}{\fp_ln_error_msg:} +% Logarithms are only valid for positive number +% \begin{macrocode} +\msg_kernel_new:nnnn { fpu } { logarithm-input-error } + { Invalid~input~to~ln~function. } + { Logarithms~can~only~be~calculated~for~positive~numbers. } +\cs_new_protected_nopar:Npn \fp_ln_error_msg: { + \msg_kernel_error:nn { fpu } { logarithm-input-error } +} +% \end{macrocode} +%\end{macro} +% %\begin{macro}{\fp_trig_overflow_msg:} % A slightly more helpful message for trigonometric overflows. % \begin{macrocode} @@ -4039,7 +5786,8 @@ \msg_kernel_error:nn { fpu } { trigonometric-overflow } } % \end{macrocode} -%\end{macro}% +%\end{macro} +% % \begin{macrocode} % % \end{macrocode} diff --git a/Master/texmf-dist/source/latex/expl3/l3tl.dtx b/Master/texmf-dist/source/latex/expl3/l3tl.dtx index c77feb5b947..b436be36ab5 100644 --- a/Master/texmf-dist/source/latex/expl3/l3tl.dtx +++ b/Master/texmf-dist/source/latex/expl3/l3tl.dtx @@ -36,7 +36,7 @@ \RequirePackage{l3names} % %\fi -\GetIdInfo$Id: l3tl.dtx 2084 2010-11-17 19:12:14Z joseph $ +\GetIdInfo$Id: l3tl.dtx 2103 2010-12-18 07:40:03Z joseph $ {L3 Experimental Token Lists} %\iffalse %<*driver> @@ -1376,7 +1376,7 @@ \tl_set:Nn \l_tl_tmpb_tl {#2} \tex_ifx:D \l_tl_tmpa_tl \l_tl_tmpb_tl \group_end: - \prg_return_false: + \prg_return_true: \tex_else:D \group_end: \prg_return_false: diff --git a/Master/texmf-dist/tex/latex/expl3/l3fp.sty b/Master/texmf-dist/tex/latex/expl3/l3fp.sty index 65366e3af16..b5bb0661edc 100644 --- a/Master/texmf-dist/tex/latex/expl3/l3fp.sty +++ b/Master/texmf-dist/tex/latex/expl3/l3fp.sty @@ -48,25 +48,18 @@ %% %% ----------------------------------------------------------------------- \RequirePackage{l3names} -\GetIdInfo$Id: l3fp.dtx 2092 2010-11-25 20:44:04Z joseph $ +\GetIdInfo$Id: l3fp.dtx 2104 2010-12-18 09:29:34Z joseph $ {L3 Experimental floating-point operations} \ProvidesExplPackage {\filename}{\filedate}{\fileversion}{\filedescription} \package_check_loaded_expl: -\int_new:N \c_forty_four -\int_set:Nn \c_forty_four { 44 } -\int_new:N \c_one_hundred -\int_set:Nn \c_one_hundred { 100 } -\int_new:N \c_one_thousand -\int_set:Nn \c_one_thousand { 1000 } -\int_new:N \c_one_million -\int_set:Nn \c_one_million { 1 000 000 } -\int_new:N \c_one_hundred_million -\int_set:Nn \c_one_hundred_million { 100 000 000 } -\int_new:N \c_five_hundred_million -\int_set:Nn \c_five_hundred_million { 500 000 000 } -\int_new:N \c_one_thousand_million -\int_set:Nn \c_one_thousand_million { 1 000 000 000 } +\int_const:Nn \c_forty_four { 44 } +\int_const:Nn \c_one_hundred { 100 } +\int_const:Nn \c_one_thousand { 1000 } +\int_const:Nn \c_one_million { 1 000 000 } +\int_const:Nn \c_one_hundred_million { 100 000 000 } +\int_const:Nn \c_five_hundred_million { 500 000 000 } +\int_const:Nn \c_one_thousand_million { 1 000 000 000 } \int_new:N \c_fp_pi_by_four_decimal_int \int_set:Nn \c_fp_pi_by_four_decimal_int { 785 398 158 } \int_new:N \c_fp_pi_by_four_extended_int @@ -79,16 +72,23 @@ \int_set:Nn \c_fp_two_pi_decimal_int { 283 185 307 } \int_new:N \c_fp_two_pi_extended_int \int_set:Nn \c_fp_two_pi_extended_int { 179 586 477 } -\tl_new:N \c_one_fp +\tl_new:N \c_e_fp +\tl_set:Nn \c_e_fp { + 2.718281828 e 0 } +\tl_new:N \c_one_fp \tl_set:Nn \c_one_fp { + 1.000000000 e 0 } -\tl_new:N \c_pi_fp +\tl_new:N \c_pi_fp \tl_set:Nn \c_pi_fp { + 3.141592654 e 0 } -\tl_new:N \c_undefined_fp +\tl_new:N \c_undefined_fp \tl_set:Nn \c_undefined_fp { X 0.000000000 e 0 } -\tl_new:N \c_zero_fp +\tl_new:N \c_zero_fp \tl_set:Nn \c_zero_fp { + 0.000000000 e 0 } +\tl_new:N \l_fp_arg_tl \int_new:N \l_fp_count_int \int_new:N \l_fp_div_offset_int +\int_new:N \l_fp_exp_integer_int +\int_new:N \l_fp_exp_decimal_int +\int_new:N \l_fp_exp_extended_int +\int_new:N \l_fp_exp_exponent_int \int_new:N \l_fp_input_a_sign_int \int_new:N \l_fp_input_a_integer_int \int_new:N \l_fp_input_a_decimal_int @@ -122,16 +122,16 @@ \tl_new:N \l_fp_round_decimal_tl \int_new:N \l_fp_round_position_int \int_new:N \l_fp_round_target_int +\tl_new:N \l_fp_sign_tl \int_new:N \l_fp_split_sign_int \int_new:N \l_fp_tmp_int \tl_new:N \l_fp_tmp_tl -\tl_new:N \l_fp_trig_arg_tl \int_new:N \l_fp_trig_octant_int \int_new:N \l_fp_trig_sign_int \int_new:N \l_fp_trig_decimal_int \int_new:N \l_fp_trig_extended_int \cs_new_protected_nopar:Npn \fp_read:N #1 { - \exp_after:wN \fp_read_aux:w #1 \q_stop + \tex_expandafter:D \fp_read_aux:w #1 \q_stop } \cs_new_protected_nopar:Npn \fp_read_aux:w #1#2 . #3 e #4 \q_stop { \tex_if:D #1 - @@ -150,29 +150,29 @@ \l_fp_split_sign_int \c_one \fp_split_sign: \use:c { l_fp_input_ #1 _sign_int } \l_fp_split_sign_int - \exp_after:wN \fp_split_exponent:w \l_fp_tmp_tl e e \q_stop #1 + \tex_expandafter:D \fp_split_exponent:w \l_fp_tmp_tl e e \q_stop #1 } \cs_new_protected_nopar:Npn \fp_split_sign: { \tex_ifnum:D \pdf_strcmp:D - { \exp_after:wN \tl_head:w \l_fp_tmp_tl ? \q_stop } { - } + { \tex_expandafter:D \tl_head:w \l_fp_tmp_tl ? \q_stop } { - } = \c_zero \tl_set:Nx \l_fp_tmp_tl { - \exp_after:wN + \tex_expandafter:D \tl_tail:w \l_fp_tmp_tl \prg_do_nothing: \q_stop } \l_fp_split_sign_int -\l_fp_split_sign_int - \exp_after:wN \fp_split_sign: + \tex_expandafter:D \fp_split_sign: \tex_else:D \tex_ifnum:D \pdf_strcmp:D - { \exp_after:wN \tl_head:w \l_fp_tmp_tl ? \q_stop } { + } + { \tex_expandafter:D \tl_head:w \l_fp_tmp_tl ? \q_stop } { + } = \c_zero \tl_set:Nx \l_fp_tmp_tl { - \exp_after:wN + \tex_expandafter:D \tl_tail:w \l_fp_tmp_tl \prg_do_nothing: \q_stop } - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_split_sign: \tex_fi:D \tex_fi:D @@ -193,7 +193,7 @@ } \cs_new_protected_nopar:Npn \fp_split_aux_iii:w #1#2 \q_stop { \l_fp_tmp_int 1 #1 \scan_stop: - \exp_after:wN \fp_split_decimal:w + \tex_expandafter:D \fp_split_decimal:w \int_use:N \l_fp_tmp_int 000000000 \q_stop } \cs_new_protected_nopar:Npn \fp_split_decimal:w #1#2#3#4#5#6#7#8#9 { @@ -212,7 +212,7 @@ \tex_ifnum:D \use:c { l_fp_input_ #4 _integer_int } < \c_one_thousand_million \tex_else:D - \exp_after:wN \fp_overflow_msg: + \tex_expandafter:D \fp_overflow_msg: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_standardise:NNNN #1#2#3#4 { @@ -220,9 +220,9 @@ \etex_numexpr:D #2 + #3 = \c_zero #1 \c_one #4 \c_zero - \exp_after:wN \use_none:nnnn + \tex_expandafter:D \use_none:nnnn \tex_else:D - \exp_after:wN \fp_standardise_aux:NNNN + \tex_expandafter:D \fp_standardise_aux:NNNN \tex_fi:D #1#2#3#4 } @@ -231,9 +231,9 @@ { \tex_ifnum:D #2 = \c_zero \tex_advance:D #3 \c_one_thousand_million - \exp_after:wN \fp_standardise_aux:w + \tex_expandafter:D \fp_standardise_aux:w \int_use:N #3 \q_stop - \exp_after:wN \fp_standardise_aux: + \tex_expandafter:D \fp_standardise_aux: \tex_fi:D } \cs_set_protected_nopar:Npn @@ -248,9 +248,9 @@ { \tex_ifnum:D #2 > \c_nine \tex_advance:D #2 \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_standardise_aux:w \int_use:N #2 - \exp_after:wN \fp_standardise_aux: + \tex_expandafter:D \fp_standardise_aux: \tex_fi:D } \cs_set_protected_nopar:Npn @@ -262,7 +262,7 @@ \tl_set:Nx \l_fp_tmp_tl { ##9 - \exp_after:wN \use_none:n \int_use:N #3 + \tex_expandafter:D \use_none:n \int_use:N #3 } #3 \l_fp_tmp_tl \scan_stop: \tex_advance:D #4 \c_one @@ -277,25 +277,25 @@ #4 \c_zero \tex_fi:D \tex_else:D - \exp_after:wN \fp_overflow_msg: + \tex_expandafter:D \fp_overflow_msg: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_standardise_aux: { } \cs_new_protected_nopar:Npn \fp_standardise_aux:w { } \cs_new_protected_nopar:Npn \fp_level_input_exponents: { \tex_ifnum:D \l_fp_input_a_exponent_int > \l_fp_input_b_exponent_int - \exp_after:wN \fp_level_input_exponents_a: + \tex_expandafter:D \fp_level_input_exponents_a: \tex_else:D - \exp_after:wN \fp_level_input_exponents_b: + \tex_expandafter:D \fp_level_input_exponents_b: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_level_input_exponents_a: { \tex_ifnum:D \l_fp_input_a_exponent_int > \l_fp_input_b_exponent_int \tex_advance:D \l_fp_input_b_integer_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_level_input_exponents_a:NNNNNNNNN \int_use:N \l_fp_input_b_integer_int - \exp_after:wN \fp_level_input_exponents_a: + \tex_expandafter:D \fp_level_input_exponents_a: \tex_fi:D } \cs_new_protected_nopar:Npn @@ -306,7 +306,7 @@ \tl_set:Nx \l_fp_tmp_tl { #9 - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_b_decimal_int } \l_fp_input_b_decimal_int \l_fp_tmp_tl \scan_stop: @@ -315,10 +315,10 @@ \cs_new_protected_nopar:Npn \fp_level_input_exponents_b: { \tex_ifnum:D \l_fp_input_b_exponent_int > \l_fp_input_a_exponent_int \tex_advance:D \l_fp_input_a_integer_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_level_input_exponents_b:NNNNNNNNN \int_use:N \l_fp_input_a_integer_int - \exp_after:wN \fp_level_input_exponents_b: + \tex_expandafter:D \fp_level_input_exponents_b: \tex_fi:D } \cs_new_protected_nopar:Npn @@ -329,7 +329,7 @@ \tl_set:Nx \l_fp_tmp_tl { #9 - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int } \l_fp_input_a_decimal_int \l_fp_tmp_tl \scan_stop: @@ -341,6 +341,18 @@ \tl_gset_eq:NN #1 \c_zero_fp } \cs_generate_variant:Nn \fp_new:N { c } +\cs_new_protected_nopar:Npn \fp_const:Nn #1#2 { + \cs_if_free:NTF #1 + { + \fp_new:N #1 + \fp_gset:Nn #1 {#2} + } + { + \msg_kernel_error:nx { variable-already-defined } + { \token_to_str:N #1 } + } +} +\cs_generate_variant:Nn \fp_const:Nn { c } \cs_new_protected_nopar:Npn \fp_zero:N #1 { \tl_set_eq:NN #1 \c_zero_fp } @@ -376,7 +388,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -398,7 +410,7 @@ \l_fp_tmp_dim \l_fp_tmp_skip \fp_split:Nn a { - \exp_after:wN \fp_set_from_dim_aux:w + \tex_expandafter:D \fp_set_from_dim_aux:w \dim_use:N \l_fp_tmp_dim } \fp_standardise:NNNN @@ -419,7 +431,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -447,7 +459,7 @@ \cs_new_eq:NN \fp_show:N \tl_show:N \cs_new_eq:NN \fp_show:c \tl_show:c \cs_new_nopar:Npn \fp_use:N #1 { - \exp_after:wN \fp_use_aux:w #1 \q_stop + \tex_expandafter:D \fp_use_aux:w #1 \q_stop } \cs_generate_variant:Nn \fp_use:N { c } \cs_new_nopar:Npn \fp_use_aux:w #1#2 e #3 \q_stop { @@ -455,13 +467,13 @@ - \tex_fi:D \tex_ifnum:D #3 > \c_zero - \exp_after:wN \fp_use_large:w + \tex_expandafter:D \fp_use_large:w \tex_else:D \tex_ifnum:D #3 < \c_zero - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_use_small:w \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_use_none:w \tex_fi:D \tex_fi:D @@ -475,9 +487,9 @@ } \cs_new_nopar:Npn \fp_use_large:w #1 . #2 e #3 \q_stop { \tex_ifnum:D #3 < \c_ten - \exp_after:wN \fp_use_large_aux_i:w + \tex_expandafter:D \fp_use_large_aux_i:w \tex_else:D - \exp_after:wN \fp_use_large_aux_ii:w + \tex_expandafter:D \fp_use_large_aux_ii:w \tex_fi:D #1#2 e #3 \q_stop } @@ -516,7 +528,7 @@ \cs_new_nopar:Npn \fp_to_dim:N #1 { \fp_use:N #1 pt } \cs_generate_variant:Nn \fp_to_dim:N { c } \cs_new_nopar:Npn \fp_to_int:N #1 { - \exp_after:wN \fp_to_int_aux:w #1 \q_stop + \tex_expandafter:D \fp_to_int_aux:w #1 \q_stop } \cs_generate_variant:Nn \fp_to_int:N { c } \cs_new_nopar:Npn \fp_to_int_aux:w #1#2 e #3 \q_stop { @@ -524,9 +536,9 @@ - \tex_fi:D \tex_ifnum:D #3 < \c_zero - \exp_after:wN \fp_to_int_small:w + \tex_expandafter:D \fp_to_int_small:w \tex_else:D - \exp_after:wN \fp_to_int_large:w + \tex_expandafter:D \fp_to_int_large:w \tex_fi:D #2 e #3 \q_stop } @@ -542,9 +554,9 @@ } \cs_new_nopar:Npn \fp_to_int_large:w #1 . #2 e #3 \q_stop { \tex_ifnum:D #3 < \c_ten - \exp_after:wN \fp_to_int_large_aux_i:w + \tex_expandafter:D \fp_to_int_large_aux_i:w \tex_else:D - \exp_after:wN \fp_to_int_large_aux_ii:w + \tex_expandafter:D \fp_to_int_large_aux_ii:w \tex_fi:D #1#2 e #3 \q_stop } @@ -590,7 +602,7 @@ \prg_replicate:nn { #2 - 9 } { 0 } } \cs_new_nopar:Npn \fp_to_tl:N #1 { - \exp_after:wN \fp_to_tl_aux:w #1 \q_stop + \tex_expandafter:D \fp_to_tl_aux:w #1 \q_stop } \cs_generate_variant:Nn \fp_to_tl:N { c } \cs_new_nopar:Npn \fp_to_tl_aux:w #1#2 e #3 \q_stop { @@ -598,17 +610,17 @@ - \tex_fi:D \tex_ifnum:D #3 < \c_zero - \exp_after:wN \fp_to_tl_small:w + \tex_expandafter:D \fp_to_tl_small:w \tex_else:D - \exp_after:wN \fp_to_tl_large:w + \tex_expandafter:D \fp_to_tl_large:w \tex_fi:D #2 e #3 \q_stop } \cs_new_nopar:Npn \fp_to_tl_large:w #1 e #2 \q_stop { \tex_ifnum:D #2 < \c_ten - \exp_after:wN \fp_to_tl_large_aux_i:w + \tex_expandafter:D \fp_to_tl_large_aux_i:w \tex_else:D - \exp_after:wN \fp_to_tl_large_aux_ii:w + \tex_expandafter:D \fp_to_tl_large_aux_ii:w \tex_fi:D #1 e #2 \q_stop } @@ -664,13 +676,13 @@ \cs_new_nopar:cpn { fp_to_tl_large_9:w } #1 . #2 \q_stop {#1#2} \cs_new_nopar:Npn \fp_to_tl_small:w #1 e #2 \q_stop { \tex_ifnum:D #2 = \c_minus_one - \exp_after:wN \fp_to_tl_small_one:w + \tex_expandafter:D \fp_to_tl_small_one:w \tex_else:D \tex_ifnum:D #2 = -\c_two - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_to_tl_small_two:w \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_to_tl_small_aux:w \tex_fi:D \tex_fi:D @@ -682,7 +694,7 @@ \etex_numexpr:D #1 \fp_use_i_to_iix:NNNNNNNNN #2 + 1 < \c_one_thousand_million 0. - \exp_after:wN \fp_to_tl_small_zeros:NNNNNNNNN + \tex_expandafter:D \fp_to_tl_small_zeros:NNNNNNNNN \tex_number:D \etex_numexpr:D #1 \fp_use_i_to_iix:NNNNNNNNN #2 + 1 @@ -701,7 +713,7 @@ \etex_numexpr:D #1 \fp_use_i_to_vii:NNNNNNNNN #2 0 + \c_ten < \c_one_thousand_million 0.0 - \exp_after:wN \fp_to_tl_small_zeros:NNNNNNNNN + \tex_expandafter:D \fp_to_tl_small_zeros:NNNNNNNNN \tex_number:D \etex_numexpr:D #1 \fp_use_i_to_vii:NNNNNNNNN #2 0 + \c_ten @@ -817,7 +829,7 @@ \fp_read:N #2 \int_set:Nn \l_fp_round_target_int { #3 - 1 } \tex_ifnum:D \l_fp_round_target_int < \c_ten - \exp_after:wN \fp_round: + \tex_expandafter:D \fp_round: \tex_fi:D \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million \cs_set_protected_nopar:Npx \fp_tmp:w @@ -832,7 +844,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -854,7 +866,7 @@ \int_set:Nn \l_fp_round_target_int { #3 + \l_fp_input_a_exponent_int } \tex_ifnum:D \l_fp_round_target_int < \c_ten - \exp_after:wN \fp_round: + \tex_expandafter:D \fp_round: \tex_fi:D \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million \cs_set_protected_nopar:Npx \fp_tmp:w @@ -869,7 +881,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -882,7 +894,7 @@ \l_fp_round_position_int \c_eight \tl_clear:N \l_fp_round_decimal_tl \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_round_aux:NNNNNNNNN \int_use:N \l_fp_input_a_decimal_int } \cs_new_protected_nopar:Npn \fp_round_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { @@ -919,7 +931,7 @@ \tex_fi:D \tex_advance:D \l_fp_round_position_int \c_minus_one \tex_ifnum:D \l_fp_round_position_int > \c_minus_one - \exp_after:wN \fp_round_loop:N + \tex_expandafter:D \fp_round_loop:N \tex_fi:D } \cs_new_protected_nopar:Npn \fp_abs:N { @@ -942,7 +954,7 @@ + \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int @@ -971,13 +983,13 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \int_use:N \l_fp_input_a_decimal_int e \int_use:N \l_fp_input_a_exponent_int } - \exp_after:wN \group_end: \exp_after:wN - #1 \exp_after:wN #2 \exp_after:wN { \l_fp_tmp_tl } + \tex_expandafter:D \group_end: \tex_expandafter:D + #1 \tex_expandafter:D #2 \tex_expandafter:D { \l_fp_tmp_tl } } \cs_new_protected_nopar:Npn \fp_add:Nn { \fp_add_aux:NNn \tl_set:Nn @@ -1006,9 +1018,9 @@ \l_fp_input_a_sign_int * \l_fp_input_b_sign_int \scan_stop: > \c_zero - \exp_after:wN \fp_add_sum: + \tex_expandafter:D \fp_add_sum: \tex_else:D - \exp_after:wN \fp_add_difference: + \tex_expandafter:D \fp_add_difference: \tex_fi:D \l_fp_output_exponent_int \l_fp_input_a_exponent_int \fp_standardise:NNNN @@ -1028,7 +1040,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million e @@ -1121,7 +1133,7 @@ \l_fp_input_b_integer_int \l_fp_input_b_decimal_int \l_fp_input_b_exponent_int - \fp_mul_int: + \fp_mul_internal: \l_fp_output_exponent_int \etex_numexpr:D \l_fp_input_a_exponent_int + \l_fp_input_b_exponent_int @@ -1153,7 +1165,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million e @@ -1162,7 +1174,7 @@ } \fp_tmp:w } -\cs_new_protected_nopar:Npn \fp_mul_int: { +\cs_new_protected_nopar:Npn \fp_mul_internal: { \fp_mul_split:NNNN \l_fp_input_a_decimal_int \l_fp_mul_a_i_int \l_fp_mul_a_ii_int \l_fp_mul_a_iii_int \fp_mul_split:NNNN \l_fp_input_b_decimal_int @@ -1199,7 +1211,7 @@ #3 ##5##6##7 \scan_stop: #4 ##8##9 \scan_stop: } - \exp_after:wN \fp_mul_split_aux:w \int_use:N #1 \q_stop + \tex_expandafter:D \fp_mul_split_aux:w \int_use:N #1 \q_stop \tex_advance:D #1 -\c_one_thousand_million } \cs_new_protected_nopar:Npn \fp_mul_product:NN #1#2 { @@ -1208,7 +1220,7 @@ } \cs_new_protected_nopar:Npn \fp_mul_end_level: { \tex_advance:D \l_fp_mul_output_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN + \tex_expandafter:D \use_i:nn \tex_expandafter:D \fp_mul_end_level:NNNNNNNNN \int_use:N \l_fp_mul_output_int } \cs_new_protected_nopar:Npn \fp_mul_end_level:NNNNNNNNN @@ -1224,7 +1236,6 @@ } \cs_generate_variant:Nn \fp_div:Nn { c } \cs_generate_variant:Nn \fp_gdiv:Nn { c } - \cs_new_protected_nopar:Npn \fp_div_aux:NNn #1#2#3 { \group_begin: \fp_read:N #2 @@ -1254,13 +1265,13 @@ #1 \exp_not:N #2 { \c_zero_fp } } \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN - \fp_div_aux: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_div_internal: \tex_fi:D \tex_fi:D \fp_tmp:w #1#2 } -\cs_new_protected_nopar:Npn \fp_div_aux: { +\cs_new_protected_nopar:Npn \fp_div_internal: { \l_fp_output_integer_int \c_zero \l_fp_output_decimal_int \c_zero \cs_set_eq:NN \fp_div_store: \fp_div_store_integer: @@ -1297,7 +1308,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million \scan_stop: @@ -1312,30 +1323,30 @@ \fp_div_store: \tex_multiply:D \l_fp_input_a_integer_int \c_ten \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million - \exp_after:wN \fp_div_loop_step:w + \tex_expandafter:D \fp_div_loop_step:w \int_use:N \l_fp_input_a_decimal_int \q_stop \tex_ifnum:D \etex_numexpr:D \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int > \c_zero \tex_ifnum:D \l_fp_div_offset_int > \c_zero - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_div_loop: \tex_fi:D \tex_fi:D } \cs_new_protected_nopar:Npn \fp_div_divide: { \tex_ifnum:D \l_fp_input_a_integer_int > \l_fp_input_b_integer_int - \exp_after:wN \fp_div_divide_aux: + \tex_expandafter:D \fp_div_divide_aux: \tex_else:D \tex_ifnum:D \l_fp_input_a_integer_int < \l_fp_input_b_integer_int \tex_else:D \tex_ifnum:D \l_fp_input_a_decimal_int < \l_fp_input_b_decimal_int \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN - \exp_after:wN \exp_after:wN \exp_after:wN - \exp_after:wN \fp_div_divide_aux: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_div_divide_aux: \tex_fi:D \tex_fi:D \tex_fi:D @@ -1430,6 +1441,7 @@ \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_iv_int \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_iii_int \fp_mul_product:NN \l_fp_mul_a_iv_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_v_int \l_fp_mul_b_i_int \fp_mul_end_level: \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_iv_int \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_iii_int @@ -1450,6 +1462,65 @@ \fp_mul_end_level: #5 0 \l_fp_mul_output_tl \scan_stop: } +\cs_new_protected_nopar:Npn \fp_mul:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \fp_mul_split:NNNN #2 + \l_fp_mul_a_i_int \l_fp_mul_a_ii_int \l_fp_mul_a_iii_int + \fp_mul_split:NNNN #3 + \l_fp_mul_a_iv_int \l_fp_mul_a_v_int \l_fp_mul_a_vi_int + \fp_mul_split:NNNN #5 + \l_fp_mul_b_i_int \l_fp_mul_b_ii_int \l_fp_mul_b_iii_int + \fp_mul_split:NNNN #6 + \l_fp_mul_b_iv_int \l_fp_mul_b_v_int \l_fp_mul_b_vi_int + \l_fp_mul_output_int \c_zero + \tl_clear:N \l_fp_mul_output_tl + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_vi_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_v_int + \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_iv_int + \fp_mul_product:NN \l_fp_mul_a_iv_int \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_v_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_vi_int \l_fp_mul_b_i_int + \tex_divide:D \l_fp_mul_output_int \c_one_thousand + \fp_mul_product:NN #1 \l_fp_mul_b_vi_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_v_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_iv_int + \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_iv_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_v_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_vi_int #4 + \fp_mul_end_level: + \fp_mul_product:NN #1 \l_fp_mul_b_v_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_iv_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_iv_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_v_int #4 + \fp_mul_end_level: + \fp_mul_product:NN #1 \l_fp_mul_b_iv_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_iii_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_iv_int #4 + \fp_mul_end_level: + #9 0 \l_fp_mul_output_tl \scan_stop: + \tl_clear:N \l_fp_mul_output_tl + \fp_mul_product:NN #1 \l_fp_mul_b_iii_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_ii_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_iii_int #4 + \fp_mul_end_level: + \fp_mul_product:NN #1 \l_fp_mul_b_ii_int + \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_ii_int #4 + \fp_mul_end_level: + \fp_mul_product:NN #1 \l_fp_mul_b_i_int + \fp_mul_product:NN \l_fp_mul_a_i_int #4 + \fp_mul_end_level: + #8 0 \l_fp_mul_output_tl \scan_stop: + \tl_clear:N \l_fp_mul_output_tl + \fp_mul_product:NN #1 #4 + \fp_mul_end_level: + #7 0 \l_fp_mul_output_tl \scan_stop: +} \cs_new_protected_nopar:Npn \fp_div_integer:NNNNN #1#2#3#4#5 { \l_fp_tmp_int #1 \tex_divide:D \l_fp_tmp_int #3 @@ -1466,52 +1537,46 @@ \tex_advancd:D #5 -\c_one_thousand_million \tex_fi:D } -\cs_new_protected_nopar:Npn \fp_trig_normalise: { - \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten - \l_fp_input_a_extended_int \c_zero - \fp_trig_normalise_aux_i: - \fp_trig_normalise_aux_ii: - \fp_trig_normalise_aux_iii: - \tex_ifnum:D \l_fp_input_a_integer_int < \c_zero - \l_fp_input_a_sign_int -\l_fp_input_a_sign_int - \l_fp_input_a_integer_int -\l_fp_input_a_integer_int - \tex_fi:D - \exp_after:wN \fp_trig_octant: - \tex_else:D - \l_fp_input_a_sign_int \c_one - \l_fp_output_integer_int \c_zero - \l_fp_output_decimal_int \c_zero - \l_fp_output_exponent_int \c_zero - \exp_after:wN \fp_trig_overflow_msg: - \tex_fi:D +\cs_new_protected_nopar:Npn \fp_extended_normalise: { + \fp_extended_normalise_aux_i: + \fp_extended_normalise_aux_ii: } -\cs_new_protected_nopar:Npn \fp_trig_normalise_aux_i: { +\cs_new_protected_nopar:Npn \fp_extended_normalise_aux_i: { \tex_ifnum:D \l_fp_input_a_exponent_int > \c_zero \tex_multiply:D \l_fp_input_a_integer_int \c_ten \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million - \exp_after:wN \fp_trig_normalise_aux:w + \tex_expandafter:D \fp_extended_normalise_aux_i:w \int_use:N \l_fp_input_a_decimal_int \q_stop - \exp_after:wN \fp_trig_normalise_aux_i: + \tex_expandafter:D \fp_extended_normalise_aux_i: \tex_fi:D } \cs_new_protected_nopar:Npn - \fp_trig_normalise_aux:w #1#2#3#4#5#6#7#8#9 \q_stop { + \fp_extended_normalise_aux_i:w #1#2#3#4#5#6#7#8#9 \q_stop { \l_fp_input_a_integer_int \etex_numexpr:D \l_fp_input_a_integer_int + #2 \scan_stop: \l_fp_input_a_decimal_int #3#4#5#6#7#8#9 0 \scan_stop: + \tex_advance:D \l_fp_input_a_extended_int \c_one_thousand_million + \tex_expandafter:D \fp_extended_normalise_aux_ii:w + \int_use:N \l_fp_input_a_extended_int \q_stop +} +\cs_new_protected_nopar:Npn + \fp_extended_normalise_aux_ii:w #1#2#3#4#5#6#7#8#9 \q_stop { + \l_fp_input_a_decimal_int + \etex_numexpr:D \l_fp_input_a_decimal_int + #2 \scan_stop: + \l_fp_input_a_extended_int #3#4#5#6#7#8#9 0 \scan_stop: \tex_advance:D \l_fp_input_a_exponent_int \c_minus_one } -\cs_new_protected_nopar:Npn \fp_trig_normalise_aux_ii: { +\cs_new_protected_nopar:Npn \fp_extended_normalise_aux_ii: { \tex_ifnum:D \l_fp_input_a_exponent_int < \c_zero \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million - \exp_after:wN \use_i:nn \exp_after:wN - \fp_trig_normalise_aux:NNNNNNNNN + \tex_expandafter:D \use_i:nn \tex_expandafter:D + \fp_extended_normalise_ii_aux:NNNNNNNNN \int_use:N \l_fp_input_a_decimal_int - \exp_after:wN \fp_trig_normalise_aux_ii: + \tex_expandafter:D \fp_extended_normalise_aux_ii: \tex_fi:D } \cs_new_protected_nopar:Npn - \fp_trig_normalise_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \fp_extended_normalise_ii_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { \tex_ifnum:D \l_fp_input_a_integer_int = \c_zero \l_fp_input_a_decimal_int #1#2#3#4#5#6#7#8 \scan_stop: \tex_else:D @@ -1532,7 +1597,64 @@ \l_fp_input_a_extended_int \l_fp_tmp_tl \scan_stop: \tex_advance:D \l_fp_input_a_exponent_int \c_one } -\cs_new_protected_nopar:Npn \fp_trig_normalise_aux_iii: { +\cs_new_protected_nopar:Npn \fp_extended_normalise_output: { + \tex_ifnum:D \l_fp_output_integer_int > \c_nine + \tex_advance:D \l_fp_output_integer_int \c_one_thousand_million + \tex_expandafter:D \use_i:nn \tex_expandafter:D + \fp_extended_normalise_output_aux_i:NNNNNNNNN + \int_use:N \l_fp_output_integer_int + \tex_expandafter:D \fp_extended_normalise_output: + \tex_fi:D +} +\cs_new_protected_nopar:Npn + \fp_extended_normalise_output_aux_i:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \l_fp_output_integer_int #1#2#3#4#5#6#7#8 \scan_stop: + \tex_advance:D \l_fp_output_decimal_int \c_one_thousand_million + \tl_set:Nx \l_fp_tmp_tl + { + #9 + \tex_expandafter:D \use_none:n + \int_use:N \l_fp_output_decimal_int + } + \tex_expandafter:D \fp_extended_normalise_output_aux_ii:NNNNNNNNN + \l_fp_tmp_tl +} +\cs_new_protected_nopar:Npn + \fp_extended_normalise_output_aux_ii:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \l_fp_output_decimal_int #1#2#3#4#5#6#7#8#9 \scan_stop: + \fp_extended_normalise_output_aux:N +} +\cs_new_protected_nopar:Npn \fp_extended_normalise_output_aux:N #1 { + \tex_advance:D \l_fp_output_extended_int \c_one_thousand_million + \tex_divide:D \l_fp_output_extended_int \c_ten + \tl_set:Nx \l_fp_tmp_tl + { + #1 + \tex_expandafter:D \use_none:n + \int_use:N \l_fp_output_extended_int + } + \l_fp_output_extended_int \l_fp_tmp_tl \scan_stop: + \tex_advance:D \l_fp_output_exponent_int \c_one +} +\cs_new_protected_nopar:Npn \fp_trig_normalise: { + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten + \l_fp_input_a_extended_int \c_zero + \fp_extended_normalise: + \fp_trig_normalise_aux: + \tex_ifnum:D \l_fp_input_a_integer_int < \c_zero + \l_fp_input_a_sign_int -\l_fp_input_a_sign_int + \l_fp_input_a_integer_int -\l_fp_input_a_integer_int + \tex_fi:D + \tex_expandafter:D \fp_trig_octant: + \tex_else:D + \l_fp_input_a_sign_int \c_one + \l_fp_output_integer_int \c_zero + \l_fp_output_decimal_int \c_zero + \l_fp_output_exponent_int \c_zero + \tex_expandafter:D \fp_trig_overflow_msg: + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_trig_normalise_aux: { \tex_ifnum:D \l_fp_input_a_integer_int > \c_three \fp_sub:NNNNNNNNN \l_fp_input_a_integer_int \l_fp_input_a_decimal_int @@ -1540,7 +1662,7 @@ \c_six \c_fp_two_pi_decimal_int \c_fp_two_pi_extended_int \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_extended_int - \exp_after:wN \fp_trig_normalise_aux_iii: + \tex_expandafter:D \fp_trig_normalise_aux: \tex_else:D \tex_ifnum:D \l_fp_input_a_integer_int > \c_two \tex_ifnum:D \l_fp_input_a_decimal_int > \c_fp_pi_decimal_int @@ -1550,9 +1672,9 @@ \c_six \c_fp_two_pi_decimal_int \c_fp_two_pi_extended_int \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_extended_int - \exp_after:wN \exp_after:wN \exp_after:wN - \exp_after:wN \exp_after:wN \exp_after:wN - \exp_after:wN \fp_trig_normalise_aux_iii: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_trig_normalise_aux: \tex_fi:D \tex_fi:D \tex_fi:D @@ -1583,7 +1705,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_extended_int \tex_advance:D \l_fp_trig_octant_int \c_one - \exp_after:wN \fp_trig_octant_aux: + \tex_expandafter:D \fp_trig_octant_aux: \tex_else:D \tex_ifnum:D \l_fp_input_a_decimal_int > \c_fp_pi_by_four_decimal_int @@ -1595,7 +1717,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_extended_int \tex_advance:D \l_fp_trig_octant_int \c_one - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_trig_octant_aux: \tex_fi:D \tex_fi:D @@ -1616,7 +1738,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_exponent_int - \tl_set:Nx \l_fp_trig_arg_tl + \tl_set:Nx \l_fp_arg_tl { \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero - @@ -1625,7 +1747,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_input_a_decimal_int + \c_one_thousand_million e @@ -1635,21 +1757,21 @@ \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: - #1 \exp_not:N #2 { \l_fp_trig_arg_tl } + #1 \exp_not:N #2 { \l_fp_arg_tl } } \tex_else:D \etex_ifcsname:D - c_fp_sin ( \l_fp_trig_arg_tl ) _tl + c_fp_sin ( \l_fp_arg_tl ) _fp \tex_endcsname:D \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_sin_aux_i: \tex_fi:D \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: #1 \exp_not:N #2 - { \use:c { c_fp_sin ( \l_fp_trig_arg_tl ) _tl } } + { \use:c { c_fp_sin ( \l_fp_arg_tl ) _fp } } } \tex_fi:D \fp_tmp:w @@ -1669,8 +1791,8 @@ \l_fp_output_integer_int \l_fp_output_decimal_int \l_fp_output_exponent_int - \tl_new:c { c_fp_sin ( \l_fp_trig_arg_tl ) _tl } - \tl_gset:cx { c_fp_sin ( \l_fp_trig_arg_tl ) _tl } + \tl_new:c { c_fp_sin ( \l_fp_arg_tl ) _fp } + \tl_gset:cx { c_fp_sin ( \l_fp_arg_tl ) _fp } { \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + @@ -1679,7 +1801,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million \scan_stop: @@ -1690,13 +1812,13 @@ \cs_new_protected_nopar:Npn \fp_sin_aux_ii: { \tex_ifcase:D \l_fp_trig_octant_int \tex_or:D - \exp_after:wN \fp_trig_calc_sin: + \tex_expandafter:D \fp_trig_calc_sin: \tex_or:D - \exp_after:wN \fp_trig_calc_cos: + \tex_expandafter:D \fp_trig_calc_cos: \tex_or:D - \exp_after:wN \fp_trig_calc_cos: + \tex_expandafter:D \fp_trig_calc_cos: \tex_or:D - \exp_after:wN \fp_trig_calc_sin: + \tex_expandafter:D \fp_trig_calc_sin: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_cos:Nn { @@ -1715,7 +1837,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_exponent_int - \tl_set:Nx \l_fp_trig_arg_tl + \tl_set:Nx \l_fp_arg_tl { \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero - @@ -1724,21 +1846,21 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_input_a_decimal_int + \c_one_thousand_million e \int_use:N \l_fp_input_a_exponent_int } - \etex_ifcsname:D c_fp_cos ( \l_fp_trig_arg_tl ) _tl \tex_endcsname:D + \etex_ifcsname:D c_fp_cos ( \l_fp_arg_tl ) _fp \tex_endcsname:D \tex_else:D - \exp_after:wN \fp_cos_aux_i: + \tex_expandafter:D \fp_cos_aux_i: \tex_fi:D \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: #1 \exp_not:N #2 - { \use:c { c_fp_cos ( \l_fp_trig_arg_tl ) _tl } } + { \use:c { c_fp_cos ( \l_fp_arg_tl ) _fp } } } \fp_tmp:w } @@ -1757,8 +1879,8 @@ \l_fp_output_integer_int \l_fp_output_decimal_int \l_fp_output_exponent_int - \tl_new:c { c_fp_cos ( \l_fp_trig_arg_tl ) _tl } - \tl_gset:cx { c_fp_cos ( \l_fp_trig_arg_tl ) _tl } + \tl_new:c { c_fp_cos ( \l_fp_arg_tl ) _fp } + \tl_gset:cx { c_fp_cos ( \l_fp_arg_tl ) _fp } { \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + @@ -1767,7 +1889,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million \scan_stop: @@ -1778,13 +1900,13 @@ \cs_new_protected_nopar:Npn \fp_cos_aux_ii: { \tex_ifcase:D \l_fp_trig_octant_int \tex_or:D - \exp_after:wN \fp_trig_calc_cos: + \tex_expandafter:D \fp_trig_calc_cos: \tex_or:D - \exp_after:wN \fp_trig_calc_sin: + \tex_expandafter:D \fp_trig_calc_sin: \tex_or:D - \exp_after:wN \fp_trig_calc_sin: + \tex_expandafter:D \fp_trig_calc_sin: \tex_or:D - \exp_after:wN \fp_trig_calc_cos: + \tex_expandafter:D \fp_trig_calc_cos: \tex_fi:D \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero \tex_ifnum:D \l_fp_trig_octant_int > \c_two @@ -1829,7 +1951,7 @@ \tex_fi:D \tex_advance:D \l_fp_output_extended_int -\l_fp_trig_extended_int \tex_advance:D \l_fp_output_decimal_int -\l_fp_trig_decimal_int - \exp_after:wN \fp_trig_calc_aux: + \tex_expandafter:D \fp_trig_calc_Taylor: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_trig_calc_sin: { @@ -1843,10 +1965,10 @@ \l_fp_trig_decimal_int \l_fp_input_a_decimal_int \l_fp_trig_extended_int \l_fp_input_a_extended_int \l_fp_count_int \c_two - \exp_after:wN \fp_trig_calc_aux: + \tex_expandafter:D \fp_trig_calc_Taylor: \tex_fi:D } -\cs_new_protected_nopar:Npn \fp_trig_calc_aux: { +\cs_new_protected_nopar:Npn \fp_trig_calc_Taylor: { \l_fp_trig_sign_int -\l_fp_trig_sign_int \fp_mul:NNNNNN \l_fp_trig_decimal_int \l_fp_trig_extended_int @@ -1896,7 +2018,7 @@ \tex_advance:D \l_fp_output_decimal_int \c_one_thousand_million \tex_fi:D \tex_fi:D - \exp_after:wN \fp_trig_calc_aux: + \tex_expandafter:D \fp_trig_calc_Taylor: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_tan:Nn { @@ -1915,7 +2037,7 @@ \l_fp_input_a_integer_int \l_fp_input_a_decimal_int \l_fp_input_a_exponent_int - \tl_set:Nx \l_fp_trig_arg_tl + \tl_set:Nx \l_fp_arg_tl { \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero - @@ -1924,7 +2046,7 @@ \tex_fi:D \int_use:N \l_fp_input_a_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_input_a_decimal_int + \c_one_thousand_million e @@ -1934,32 +2056,32 @@ \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: - #1 \exp_not:N #2 { \l_fp_trig_arg_tl } + #1 \exp_not:N #2 { \l_fp_arg_tl } } \tex_else:D \etex_ifcsname:D - c_fp_tan ( \l_fp_trig_arg_tl ) _tl + c_fp_tan ( \l_fp_arg_tl ) _fp \tex_endcsname:D \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_tan_aux_i: \tex_fi:D \cs_set_protected_nopar:Npx \fp_tmp:w { \group_end: #1 \exp_not:N #2 - { \use:c { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } } + { \use:c { c_fp_tan ( \l_fp_arg_tl ) _fp } } } \tex_fi:D \fp_tmp:w } \cs_new_protected_nopar:Npn \fp_tan_aux_i: { \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten - \exp_after:wN \fp_tan_aux_ii: + \tex_expandafter:D \fp_tan_aux_ii: \tex_else:D - \cs_new_eq:cN { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } + \cs_new_eq:cN { c_fp_tan ( \l_fp_arg_tl ) _fp } \c_zero_fp - \exp_after:wN \fp_trig_overflow_msg: + \tex_expandafter:D \fp_trig_overflow_msg: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_tan_aux_ii: { @@ -1967,14 +2089,14 @@ \fp_cos_aux_ii: \tex_ifnum:D \l_fp_input_a_decimal_int = \c_zero \tex_ifnum:D \l_fp_input_a_integer_int = \c_zero - \cs_new_eq:cN { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } + \cs_new_eq:cN { c_fp_tan ( \l_fp_arg_tl ) _fp } \c_undefined_fp \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_tan_aux_iii: \tex_fi:D \tex_else:D - \exp_after:wN \fp_tan_aux_iii: + \tex_expandafter:D \fp_tan_aux_iii: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_tan_aux_iii: { @@ -1997,14 +2119,14 @@ \l_fp_input_a_exponent_int \tex_ifnum:D \l_fp_input_a_decimal_int = \c_zero \tex_ifnum:D \l_fp_input_a_integer_int = \c_zero - \cs_new_eq:cN { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } + \cs_new_eq:cN { c_fp_tan ( \l_fp_arg_tl ) _fp } \c_zero_fp \tex_else:D - \exp_after:wN \exp_after:wN \exp_after:wN + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D \fp_tan_aux_iv: \tex_fi:D \tex_else:D - \exp_after:wN \fp_tan_aux_iv: + \tex_expandafter:D \fp_tan_aux_iv: \tex_fi:D } \cs_new_protected_nopar:Npn \fp_tan_aux_iv: { @@ -2027,8 +2149,563 @@ \l_fp_output_integer_int \l_fp_output_decimal_int \l_fp_output_exponent_int - \tl_new:c { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } - \tl_gset:cx { c_fp_tan ( \l_fp_trig_arg_tl ) _tl } + \tl_new:c { c_fp_tan ( \l_fp_arg_tl ) _fp } + \tl_gset:cx { c_fp_tan ( \l_fp_arg_tl ) _fp } + { + \tex_ifnum:D \l_fp_output_sign_int > \c_zero + + + \tex_else:D + - + \tex_fi:D + \int_use:N \l_fp_output_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_output_decimal_int + \c_one_thousand_million + \scan_stop: + e + \int_use:N \l_fp_output_exponent_int + } +} +\tl_new:c { c_fp_exp_1_tl } +\tl_set:cn { c_fp_exp_1_tl } + { { 2 } { 718281828 } { 459045235 } { 0 } } +\tl_new:c { c_fp_exp_2_tl } +\tl_set:cn { c_fp_exp_2_tl } + { { 7 } { 389056098 } { 930650227 } { 0 } } +\tl_new:c { c_fp_exp_3_tl } +\tl_set:cn { c_fp_exp_3_tl } + { { 2 } { 008553692 } { 318766774 } { 1 } } +\tl_new:c { c_fp_exp_4_tl } +\tl_set:cn { c_fp_exp_4_tl } + { { 5 } { 459815003 } { 314423908 } { 1 } } +\tl_new:c { c_fp_exp_5_tl } +\tl_set:cn { c_fp_exp_5_tl } + { { 1 } { 484131591 } { 025766034 } { 2 } } +\tl_new:c { c_fp_exp_6_tl } +\tl_set:cn { c_fp_exp_6_tl } + { { 4 } { 034287934 } { 927351226 } { 2 } } +\tl_new:c { c_fp_exp_7_tl } +\tl_set:cn { c_fp_exp_7_tl } + { { 1 } { 096633158 } { 428458599 } { 3 } } +\tl_new:c { c_fp_exp_8_tl } +\tl_set:cn { c_fp_exp_8_tl } + { { 2 } { 980957987 } { 041728275 } { 3 } } +\tl_new:c { c_fp_exp_9_tl } +\tl_set:cn { c_fp_exp_9_tl } + { { 8 } { 103083927 } { 575384008 } { 3 } } +\tl_new:c { c_fp_exp_10_tl } +\tl_set:cn { c_fp_exp_10_tl } + { { 2 } { 202646579 } { 480671652 } { 4 } } +\tl_new:c { c_fp_exp_20_tl } +\tl_set:cn { c_fp_exp_20_tl } + { { 4 } { 851651954 } { 097902280 } { 8 } } +\tl_new:c { c_fp_exp_30_tl } +\tl_set:cn { c_fp_exp_30_tl } + { { 1 } { 068647458 } { 152446215 } { 13 } } +\tl_new:c { c_fp_exp_40_tl } +\tl_set:cn { c_fp_exp_40_tl } + { { 2 } { 353852668 } { 370199854 } { 17 } } +\tl_new:c { c_fp_exp_50_tl } +\tl_set:cn { c_fp_exp_50_tl } + { { 5 } { 184705528 } { 587072464 } { 21 } } +\tl_new:c { c_fp_exp_60_tl } +\tl_set:cn { c_fp_exp_60_tl } + { { 1 } { 142007389 } { 815684284 } { 26 } } +\tl_new:c { c_fp_exp_70_tl } +\tl_set:cn { c_fp_exp_70_tl } + { { 2 } { 515438670 } { 919167006 } { 30 } } +\tl_new:c { c_fp_exp_80_tl } +\tl_set:cn { c_fp_exp_80_tl } + { { 5 } { 540622384 } { 393510053 } { 34 } } +\tl_new:c { c_fp_exp_90_tl } +\tl_set:cn { c_fp_exp_90_tl } + { { 1 } { 220403294 } { 317840802 } { 39 } } +\tl_new:c { c_fp_exp_100_tl } +\tl_set:cn { c_fp_exp_100_tl } + { { 2 } { 688117141 } { 816135448 } { 43 } } +\tl_new:c { c_fp_exp_200_tl } +\tl_set:cn { c_fp_exp_200_tl } + { { 7 } { 225973768 } { 125749258 } { 86 } } +\tl_new:c { c_fp_exp_-1_tl } +\tl_set:cn { c_fp_exp_-1_tl } + { { 3 } { 678794411 } { 71442322 } { -1 } } +\tl_new:c { c_fp_exp_-2_tl } +\tl_set:cn { c_fp_exp_-2_tl } + { { 1 } { 353352832 } { 366132692 } { -1 } } +\tl_new:c { c_fp_exp_-3_tl } +\tl_set:cn { c_fp_exp_-3_tl } + { { 4 } { 978706836 } { 786394298 } { -2 } } +\tl_new:c { c_fp_exp_-4_tl } +\tl_set:cn { c_fp_exp_-4_tl } + { { 1 } { 831563888 } { 873418029 } { -2 } } +\tl_new:c { c_fp_exp_-5_tl } +\tl_set:cn { c_fp_exp_-5_tl } + { { 6 } { 737946999 } { 085467097 } { -3 } } +\tl_new:c { c_fp_exp_-6_tl } +\tl_set:cn { c_fp_exp_-6_tl } + { { 2 } { 478752176 } { 666358423 } { -3 } } +\tl_new:c { c_fp_exp_-7_tl } +\tl_set:cn { c_fp_exp_-7_tl } + { { 9 } { 118819655 } { 545162080 } { -4 } } +\tl_new:c { c_fp_exp_-8_tl } +\tl_set:cn { c_fp_exp_-8_tl } + { { 3 } { 354626279 } { 025118388 } { -4 } } +\tl_new:c { c_fp_exp_-9_tl } +\tl_set:cn { c_fp_exp_-9_tl } + { { 1 } { 234098040 } { 866795495 } { -4 } } +\tl_new:c { c_fp_exp_-10_tl } +\tl_set:cn { c_fp_exp_-10_tl } + { { 4 } { 539992976 } { 248451536 } { -5 } } +\tl_new:c { c_fp_exp_-20_tl } +\tl_set:cn { c_fp_exp_-20_tl } + { { 2 } { 061153622 } { 438557828 } { -9 } } +\tl_new:c { c_fp_exp_-30_tl } +\tl_set:cn { c_fp_exp_-30_tl } + { { 9 } { 357622968 } { 840174605 } { -14 } } +\tl_new:c { c_fp_exp_-40_tl } +\tl_set:cn { c_fp_exp_-40_tl } + { { 4 } { 248354255 } { 291588995 } { -18 } } +\tl_new:c { c_fp_exp_-50_tl } +\tl_set:cn { c_fp_exp_-50_tl } + { { 1 } { 928749847 } { 963917783 } { -22 } } +\tl_new:c { c_fp_exp_-60_tl } +\tl_set:cn { c_fp_exp_-60_tl } + { { 8 } { 756510762 } { 696520338 } { -27 } } +\tl_new:c { c_fp_exp_-70_tl } +\tl_set:cn { c_fp_exp_-70_tl } + { { 3 } { 975449735 } { 908646808 } { -31 } } +\tl_new:c { c_fp_exp_-80_tl } +\tl_set:cn { c_fp_exp_-80_tl } + { { 1 } { 804851387 } { 845415172 } { -35 } } +\tl_new:c { c_fp_exp_-90_tl } +\tl_set:cn { c_fp_exp_-90_tl } + { { 8 } { 194012623 } { 990515430 } { -40 } } +\tl_new:c { c_fp_exp_-100_tl } +\tl_set:cn { c_fp_exp_-100_tl } + { { 3 } { 720075976 } { 020835963 } { -44 } } +\tl_new:c { c_fp_exp_-200_tl } +\tl_set:cn { c_fp_exp_-200_tl } + { { 1 } { 383896526 } { 736737530 } { -87 } } +\cs_new_protected_nopar:Npn \fp_exp:Nn { + \fp_exp_aux:NNn \tl_set:Nn +} +\cs_new_protected_nopar:Npn \fp_gexp:Nn { + \fp_exp_aux:NNn \tl_gset:Nn +} +\cs_generate_variant:Nn \fp_exp:Nn { c } +\cs_generate_variant:Nn \fp_gexp:Nn { c } +\cs_new_protected_nopar:Npn \fp_exp_aux:NNn #1#2#3 { + \group_begin: + \fp_split:Nn a {#3} + \fp_standardise:NNNN + \l_fp_input_a_sign_int + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + \l_fp_input_a_exponent_int + \l_fp_input_a_extended_int \c_zero + \tl_set:Nx \l_fp_arg_tl + { + \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero + - + \tex_else:D + + + \tex_fi:D + \int_use:N \l_fp_input_a_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_input_a_decimal_int + \c_one_thousand_million + e + \int_use:N \l_fp_input_a_exponent_int + } + \etex_ifcsname:D c_fp_exp ( \l_fp_arg_tl ) _fp \tex_endcsname:D + \tex_else:D + \tex_expandafter:D \fp_exp_internal: + \tex_fi:D + \cs_set_protected_nopar:Npx \fp_tmp:w + { + \group_end: + #1 \exp_not:N #2 + { + \etex_ifcsname:D c_fp_exp ( \l_fp_arg_tl ) _fp + \tex_endcsname:D + \use:c { c_fp_exp ( \l_fp_arg_tl ) _fp } + \tex_else:D + \c_zero_fp + \tex_fi:D + } + } + \fp_tmp:w +} +\cs_new_protected_nopar:Npn \fp_exp_internal: { + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_three + \fp_extended_normalise: + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \tex_ifnum:D \l_fp_input_a_integer_int < 230 \scan_stop: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_aux: + \tex_else:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_overflow_msg: + \tex_fi:D + \tex_else:D + \tex_ifnum:D \l_fp_input_a_integer_int < 230 \scan_stop: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_aux: + \tex_else:D + \fp_exp_const:cx { c_fp_exp ( \l_fp_arg_tl ) _fp } + { \c_zero_fp } + \tex_fi:D + \tex_fi:D + \tex_else:D + \tex_expandafter:D \fp_exp_overflow_msg: + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_exp_aux: { + \tex_ifnum:D \l_fp_input_a_integer_int > \c_zero + \tex_expandafter:D \fp_exp_integer: + \tex_else:D + \l_fp_output_integer_int \c_one + \l_fp_output_decimal_int \c_zero + \l_fp_output_extended_int \c_zero + \l_fp_output_exponent_int \c_zero + \tex_expandafter:D \fp_exp_decimal: + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_exp_integer: { + \tex_ifnum:D \l_fp_input_a_integer_int < \c_one_hundred + \l_fp_exp_integer_int \c_one + \l_fp_exp_decimal_int \c_zero + \l_fp_exp_extended_int \c_zero + \l_fp_exp_exponent_int \c_zero + \tex_expandafter:D \fp_exp_integer_tens: + \tex_else:D + \tl_set:Nx \l_fp_tmp_tl + { + \tex_expandafter:D \use_i:nnn + \int_use:N \l_fp_input_a_integer_int + } + \l_fp_input_a_integer_int + \etex_numexpr:D + \l_fp_input_a_integer_int - \l_fp_tmp_tl 00 + \scan_stop: + \tex_ifnum:D \l_fp_input_a_sign_int < \c_zero + \tex_ifnum:D \l_fp_output_integer_int > 200 \scan_stop: + \fp_exp_const:cx { c_fp_exp ( \l_fp_arg_tl ) _fp } + { \c_zero_fp } + \tex_else:D + \fp_exp_integer_const:n { - \l_fp_tmp_tl 00 } + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_integer_tens: + \tex_fi:D + \tex_else:D + \fp_exp_integer_const:n { \l_fp_tmp_tl 00 } + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_exp_integer_tens: + \tex_fi:D + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_exp_integer_tens: { + \l_fp_output_integer_int \l_fp_exp_integer_int + \l_fp_output_decimal_int \l_fp_exp_decimal_int + \l_fp_output_extended_int \l_fp_exp_extended_int + \l_fp_output_exponent_int \l_fp_exp_exponent_int + \tex_ifnum:D \l_fp_input_a_integer_int > \c_nine + \tl_set:Nx \l_fp_tmp_tl + { + \tex_expandafter:D \use_i:nn + \int_use:N \l_fp_input_a_integer_int + } + \l_fp_input_a_integer_int + \etex_numexpr:D + \l_fp_input_a_integer_int - \l_fp_tmp_tl 0 + \scan_stop: + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \fp_exp_integer_const:n { \l_fp_tmp_tl 0 } + \tex_else:D + \fp_exp_integer_const:n { - \l_fp_tmp_tl 0 } + \tex_fi:D + \fp_mul:NNNNNNNNN + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_advance:D \l_fp_output_exponent_int \l_fp_exp_exponent_int + \fp_extended_normalise_output: + \tex_fi:D + \fp_exp_integer_units: +} +\cs_new_protected_nopar:Npn \fp_exp_integer_units: { + \tex_ifnum:D \l_fp_input_a_integer_int > \c_zero + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \fp_exp_integer_const:n { \int_use:N \l_fp_input_a_integer_int } + \tex_else:D + \fp_exp_integer_const:n + { - \int_use:N \l_fp_input_a_integer_int } + \tex_fi:D + \fp_mul:NNNNNNNNN + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_advance:D \l_fp_output_exponent_int \l_fp_exp_exponent_int + \fp_extended_normalise_output: + \tex_fi:D + \fp_exp_decimal: +} +\cs_new_protected_nopar:Npn \fp_exp_integer_const:n #1 { + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_exp_integer_const:nnnn + \tex_csname:D c_fp_exp_ #1 _tl \tex_endcsname:D +} +\cs_new_protected_nopar:Npn \fp_exp_integer_const:nnnn #1#2#3#4 { + \l_fp_exp_integer_int #1 \scan_stop: + \l_fp_exp_decimal_int #2 \scan_stop: + \l_fp_exp_extended_int #3 \scan_stop: + \l_fp_exp_exponent_int #4 \scan_stop: +} +\cs_new_protected_nopar:Npn \fp_exp_decimal: { + \tex_ifnum:D \l_fp_input_a_decimal_int > \c_zero + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \l_fp_exp_integer_int \c_one + \l_fp_exp_decimal_int \l_fp_input_a_decimal_int + \l_fp_exp_extended_int \l_fp_input_a_extended_int + \tex_else:D + \l_fp_exp_integer_int \c_zero + \tex_ifnum:D \l_fp_exp_extended_int = \c_zero + \l_fp_exp_decimal_int + \etex_numexpr:D + \c_one_thousand_million - \l_fp_input_a_decimal_int + \scan_stop: + \l_fp_exp_extended_int \c_zero + \tex_else:D + \l_fp_exp_decimal_int + \etex_numexpr:D + 999999999 - \l_fp_input_a_decimal_int + \scan_stop: + \l_fp_exp_extended_int + \etex_numexpr:D + \c_one_thousand_million - \l_fp_input_a_extended_int + \scan_stop: + \tex_fi:D + \tex_fi:D + \l_fp_input_b_sign_int \l_fp_input_a_sign_int + \l_fp_input_b_decimal_int \l_fp_input_a_decimal_int + \l_fp_input_b_extended_int \l_fp_input_a_extended_int + \l_fp_count_int \c_one + \fp_exp_Taylor: + \fp_mul:NNNNNNNNN + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_fi:D + \tex_ifnum:D \l_fp_output_extended_int < \c_five_hundred_million + \tex_else:D + \tex_advance:D \l_fp_output_decimal_int \c_one + \tex_ifnum:D \l_fp_output_decimal_int < \c_one_thousand_million + \tex_else:D + \l_fp_output_decimal_int \c_zero + \tex_advance:D \l_fp_output_integer_int \c_one + \tex_fi:D + \tex_fi:D + \fp_standardise:NNNN + \l_fp_output_sign_int + \l_fp_output_integer_int + \l_fp_output_decimal_int + \l_fp_output_exponent_int + \fp_exp_const:cx { c_fp_exp ( \l_fp_arg_tl ) _fp } + { + + + \int_use:N \l_fp_output_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_output_decimal_int + \c_one_thousand_million + \scan_stop: + e + \int_use:N \l_fp_output_exponent_int + } +} +\cs_new_protected_nopar:Npn \fp_exp_Taylor: { + \tex_advance:D \l_fp_count_int \c_one + \tex_multiply:D \l_fp_input_b_sign_int \l_fp_input_a_sign_int + \fp_mul:NNNNNN + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \fp_div_integer:NNNNN + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \l_fp_count_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_b_decimal_int + \l_fp_input_b_extended_int + > \c_zero + \tex_ifnum:D \l_fp_input_b_sign_int > \c_zero + \tex_advance:D \l_fp_exp_decimal_int \l_fp_input_b_decimal_int + \tex_advance:D \l_fp_exp_extended_int + \l_fp_input_b_extended_int + \tex_ifnum:D \l_fp_exp_extended_int < \c_one_thousand_million + \tex_else:D + \tex_advance:D \l_fp_exp_decimal_int \c_one + \tex_advance:D \l_fp_exp_extended_int + -\c_one_thousand_million + \tex_fi:D + \tex_ifnum:D \l_fp_exp_decimal_int < \c_one_thousand_million + \tex_else:D + \tex_advance:D \l_fp_exp_integer_int \c_one + \tex_advance:D \l_fp_exp_decimal_int + -\c_one_thousand_million + \tex_fi:D + \tex_else:D + \tex_advance:D \l_fp_exp_decimal_int -\l_fp_input_b_decimal_int + \tex_advance:D \l_fp_exp_extended_int + -\l_fp_input_a_extended_int + \tex_ifnum:D \l_fp_exp_extended_int < \c_zero + \tex_advance:D \l_fp_exp_decimal_int \c_minus_one + \tex_advance:D \l_fp_exp_extended_int \c_one_thousand_million + \tex_fi:D + \tex_ifnum:D \l_fp_exp_decimal_int < \c_zero + \tex_advance:D \l_fp_exp_integer_int \c_minus_one + \tex_advance:D \l_fp_exp_decimal_int \c_one_thousand_million + \tex_fi:D + \tex_fi:D + \tex_expandafter:D \fp_exp_Taylor: + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_exp_const:Nx #1#2 { + \tl_new:N #1 + \tl_gset:Nx #1 {#2} +} +\cs_generate_variant:Nn \fp_exp_const:Nx { c } +\tl_new:c { c_fp_ln_10_1_tl } +\tl_set:cn { c_fp_ln_10_1_tl } + { { 2 } { 302585092 } { 994045684 } { 0 } } +\tl_new:c { c_fp_ln_10_2_tl } +\tl_set:cn { c_fp_ln_10_2_tl } + { { 4 } { 605170185 } { 988091368 } { 0 } } +\tl_new:c { c_fp_ln_10_3_tl } +\tl_set:cn { c_fp_ln_10_3_tl } + { { 6 } { 907755278 } { 982137052 } { 0 } } +\tl_new:c { c_fp_ln_10_4_tl } +\tl_set:cn { c_fp_ln_10_4_tl } + { { 9 } { 210340371 } { 976182736 } { 0 } } +\tl_new:c { c_fp_ln_10_5_tl } +\tl_set:cn { c_fp_ln_10_5_tl } + { { 1 } { 151292546 } { 497022842 } { 1 } } +\tl_new:c { c_fp_ln_10_6_tl } +\tl_set:cn { c_fp_ln_10_6_tl } + { { 1 } { 381551055 } { 796427410 } { 1 } } +\tl_new:c { c_fp_ln_10_7_tl } +\tl_set:cn { c_fp_ln_10_7_tl } + { { 1 } { 611809565 } { 095831979 } { 1 } } +\tl_new:c { c_fp_ln_10_8_tl } +\tl_set:cn { c_fp_ln_10_8_tl } + { { 1 } { 842068074 } { 395226547 } { 1 } } +\tl_new:c { c_fp_ln_10_9_tl } +\tl_set:cn { c_fp_ln_10_9_tl } + { { 2 } { 072326583 } { 694641116 } { 1 } } +\tl_new:c { c_fp_ln_2_1_tl } +\tl_set:cn { c_fp_ln_2_1_tl } + { { 0 } { 693147180 } { 559945309 } { 0 } } +\tl_new:c { c_fp_ln_2_2_tl } +\tl_set:cn { c_fp_ln_2_2_tl } + { { 1 } { 386294361 } { 119890618 } { 0 } } +\tl_new:c { c_fp_ln_2_3_tl } +\tl_set:cn { c_fp_ln_2_3_tl } + { { 2 } { 079441541 } { 679835928 } { 0 } } +\cs_new_protected_nopar:Npn \fp_ln:Nn { + \fp_ln_aux:NNn \tl_set:Nn +} +\cs_new_protected_nopar:Npn \fp_gln:Nn { + \fp_ln_aux:NNn \tl_gset:Nn +} +\cs_generate_variant:Nn \fp_ln:Nn { c } +\cs_generate_variant:Nn \fp_gln:Nn { c } +\cs_new_protected_nopar:Npn \fp_ln_aux:NNn #1#2#3 { + \group_begin: + \fp_split:Nn a {#3} + \fp_standardise:NNNN + \l_fp_input_a_sign_int + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + \l_fp_input_a_exponent_int + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + > \c_zero + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_ln_aux: + \tex_else:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 \exp_not:N ##2 { \c_zero_fp } + } + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_ln_error_msg: + \tex_fi:D + \tex_else:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 \exp_not:N ##2 { \c_zero_fp } + } + \tex_expandafter:D \fp_ln_error_msg: + \tex_fi:D + \fp_tmp:w #1 #2 +} +\cs_new_protected_nopar:Npn \fp_ln_aux: { + \tl_set:Nx \l_fp_arg_tl + { + + + \int_use:N \l_fp_input_a_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_input_a_decimal_int + \c_one_thousand_million + e + \int_use:N \l_fp_input_a_exponent_int + } + \etex_ifcsname:D c_fp_ln ( \l_fp_arg_tl ) _fp \tex_endcsname:D + \tex_else:D + \tex_expandafter:D \fp_ln_exponent: + \tex_fi:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 \exp_not:N ##2 + { \use:c { c_fp_ln ( \l_fp_arg_tl ) _fp } } + } +} +\cs_new_protected_nopar:Npn \fp_ln_exponent: { + \fp_ln_internal: + \tex_ifnum:D \l_fp_output_extended_int < \c_five_hundred_million + \tex_else:D + \tex_advance:D \l_fp_output_decimal_int \c_one + \tex_ifnum:D \l_fp_output_decimal_int < \c_one_thousand_million + \tex_else:D + \l_fp_output_decimal_int \c_zero + \tex_advance:D \l_fp_output_integer_int \c_one + \tex_fi:D + \tex_fi:D + \fp_standardise:NNNN + \l_fp_output_sign_int + \l_fp_output_integer_int + \l_fp_output_decimal_int + \l_fp_output_exponent_int + \tl_new:c { c_fp_ln ( \l_fp_arg_tl ) _fp } + \tl_gset:cx { c_fp_ln ( \l_fp_arg_tl ) _fp } { \tex_ifnum:D \l_fp_output_sign_int > \c_zero + @@ -2037,7 +2714,7 @@ \tex_fi:D \int_use:N \l_fp_output_integer_int . - \exp_after:wN \use_none:n + \tex_expandafter:D \use_none:n \tex_number:D \etex_numexpr:D \l_fp_output_decimal_int + \c_one_thousand_million \scan_stop: @@ -2045,21 +2722,445 @@ \int_use:N \l_fp_output_exponent_int } } -\prg_new_conditional:Npnn \fp_if_undefined:N #1 { p , T , F , TF } { +\cs_new_protected_nopar:Npn \fp_ln_internal: { + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_zero + \l_fp_input_a_exponent_int -\l_fp_input_a_exponent_int + \l_fp_output_sign_int \c_minus_one + \tex_else:D + \l_fp_output_sign_int \c_one + \tex_fi:D + \tex_ifnum:D \l_fp_input_a_exponent_int > \c_nine + \tl_set:Nx \l_fp_tmp_tl + { + \tex_expandafter:D \use_i:nn + \int_use:N \l_fp_input_a_exponent_int + } + \l_fp_input_a_exponent_int + \etex_numexpr:D + \l_fp_input_a_exponent_int - \l_fp_tmp_tl 0 + \scan_stop: + \fp_ln_const:nn { 10 } { \l_fp_tmp_tl } + \tex_advance:D \l_fp_exp_exponent_int \c_one + \l_fp_output_integer_int \l_fp_exp_integer_int + \l_fp_output_decimal_int \l_fp_exp_decimal_int + \l_fp_output_extended_int \l_fp_exp_extended_int + \l_fp_output_exponent_int \l_fp_exp_exponent_int + \tex_else:D + \l_fp_output_integer_int \c_zero + \l_fp_output_decimal_int \c_zero + \l_fp_output_extended_int \c_zero + \l_fp_output_exponent_int \c_zero + \tex_fi:D + \fp_ln_exponent_units: +} +\cs_new_protected_nopar:Npn \fp_ln_exponent_units: { + \tex_ifnum:D \l_fp_input_a_exponent_int > \c_zero + \fp_ln_const:nn { 10 } { \int_use:N \l_fp_input_a_exponent_int } + \fp_ln_normalise: + \fp_add:NNNNNNNNN + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_fi:D + \fp_ln_mantissa: +} +\cs_new_protected_nopar:Npn \fp_ln_normalise: { + \tex_ifnum:D \l_fp_exp_exponent_int < \l_fp_output_exponent_int + \tex_advance:D \l_fp_exp_decimal_int \c_one_thousand_million + \tex_expandafter:D \use_i:nn \tex_expandafter:D + \fp_ln_normalise_aux:NNNNNNNNN + \int_use:N \l_fp_exp_decimal_int + \tex_expandafter:D \fp_ln_normalise: + \tex_fi:D +} +\cs_new_protected_nopar:Npn + \fp_ln_normalise_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \tex_ifnum:D \l_fp_exp_integer_int = \c_zero + \l_fp_exp_decimal_int #1#2#3#4#5#6#7#8 \scan_stop: + \tex_else:D + \tl_set:Nx \l_fp_tmp_tl + { + \int_use:N \l_fp_exp_integer_int + #1#2#3#4#5#6#7#8 + } + \l_fp_exp_integer_int \c_zero + \l_fp_exp_decimal_int \l_fp_tmp_tl \scan_stop: + \tex_fi:D + \tex_divide:D \l_fp_exp_extended_int \c_ten + \tl_set:Nx \l_fp_tmp_tl + { + #9 + \int_use:N \l_fp_exp_extended_int + } + \l_fp_exp_extended_int \l_fp_tmp_tl \scan_stop: + \tex_advance:D \l_fp_exp_exponent_int \c_one +} +\cs_new_protected_nopar:Npn \fp_ln_mantissa: { + \l_fp_count_int \c_zero + \l_fp_input_a_extended_int \c_zero + \fp_ln_mantissa_aux: + \tex_ifnum:D \l_fp_count_int > \c_zero + \fp_ln_const:nn { 2 } { \int_use:N \l_fp_count_int } + \fp_ln_normalise: + \tex_ifnum:D \l_fp_output_sign_int > \c_zero + \tex_expandafter:D \fp_add:NNNNNNNNN + \tex_else:D + \tex_expandafter:D \fp_sub:NNNNNNNNN + \tex_fi:D + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \l_fp_exp_integer_int \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \tex_fi:D + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int > \c_one + \scan_stop: + \tex_expandafter:D \fp_ln_Taylor: + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_ln_mantissa_aux: { + \tex_ifnum:D \l_fp_input_a_integer_int > \c_one + \tex_advance:D \l_fp_count_int \c_one + \fp_ln_mantissa_divide_two: + \tex_expandafter:D \fp_ln_mantissa_aux: + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_ln_mantissa_divide_two: { + \tex_ifodd:D \l_fp_input_a_decimal_int + \tex_advance:D \l_fp_input_a_extended_int \c_one_thousand_million + \tex_fi:D + \tex_ifodd:D \l_fp_input_a_integer_int + \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million + \tex_fi:D + \tex_divide:D \l_fp_input_a_integer_int \c_two + \tex_divide:D \l_fp_input_a_decimal_int \c_two + \tex_divide:D \l_fp_input_a_extended_int \c_two +} +\cs_new_protected_nopar:Npn \fp_ln_const:nn #1#2 { + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_exp_integer_const:nnnn + \tex_csname:D c_fp_ln_ #1 _ #2 _tl \tex_endcsname:D +} +\cs_new_protected_nopar:Npn \fp_ln_Taylor: { + \group_begin: + \l_fp_input_a_integer_int \c_zero + \l_fp_input_a_exponent_int \c_zero + \l_fp_input_b_integer_int \c_two + \l_fp_input_b_decimal_int \l_fp_input_a_decimal_int + \l_fp_input_b_exponent_int \c_zero + \fp_div_internal: + \fp_ln_fixed: + \l_fp_input_a_integer_int \l_fp_output_integer_int + \l_fp_input_a_decimal_int \l_fp_output_decimal_int + \l_fp_input_a_exponent_int \l_fp_output_exponent_int + \l_fp_input_a_extended_int \c_zero + \l_fp_output_decimal_int \c_zero + \l_fp_output_decimal_int \l_fp_input_a_decimal_int + \l_fp_output_extended_int \l_fp_input_a_extended_int + \fp_mul:NNNNNN + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \l_fp_count_int \c_one + \fp_ln_Taylor_aux: + \cs_set_protected_nopar:Npx \fp_tmp:w + { + \group_end: + \exp_not:N \l_fp_exp_decimal_int + \int_use:N \l_fp_output_decimal_int \scan_stop: + \exp_not:N \l_fp_exp_extended_int + \int_use:N \l_fp_output_extended_int \scan_stop: + \exp_not:N \l_fp_exp_exponent_int + \int_use:N \l_fp_output_exponent_int \scan_stop: + } + \fp_tmp:w + \tex_advance:D \l_fp_exp_decimal_int \l_fp_exp_decimal_int + \tex_ifnum:D \l_fp_exp_extended_int < \c_five_hundred_million + \tex_else:D + \tex_advance:D \l_fp_exp_extended_int -\c_five_hundred_million + \tex_advance:D \l_fp_exp_decimal_int \c_one + \tex_fi:D + \tex_advance:D \l_fp_exp_extended_int \l_fp_exp_extended_int + \tex_ifnum:D \l_fp_output_sign_int > \c_zero + \tex_expandafter:D \fp_add:NNNNNNNNN + \tex_else:D + \tex_expandafter:D \fp_sub:NNNNNNNNN + \tex_fi:D + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int + \c_zero \l_fp_exp_decimal_int \l_fp_exp_extended_int + \l_fp_output_integer_int \l_fp_output_decimal_int + \l_fp_output_extended_int +} +\cs_new_protected_nopar:Npn \fp_ln_fixed: { + \tex_ifnum:D \l_fp_output_exponent_int < \c_zero + \tex_advance:D \l_fp_output_decimal_int \c_one_thousand_million + \tex_expandafter:D \use_i:nn \tex_expandafter:D + \fp_ln_fixed_aux:NNNNNNNNN + \int_use:N \l_fp_output_decimal_int + \tex_expandafter:D \fp_ln_fixed: + \tex_fi:D +} +\cs_new_protected_nopar:Npn + \fp_ln_fixed_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { + \tex_ifnum:D \l_fp_output_integer_int = \c_zero + \l_fp_output_decimal_int #1#2#3#4#5#6#7#8 \scan_stop: + \tex_else:D + \tl_set:Nx \l_fp_tmp_tl + { + \int_use:N \l_fp_output_integer_int + #1#2#3#4#5#6#7#8 + } + \l_fp_output_integer_int \c_zero + \l_fp_output_decimal_int \l_fp_tmp_tl \scan_stop: + \tex_fi:D + \tex_advance:D \l_fp_output_exponent_int \c_one +} +\cs_new_protected_nopar:Npn \fp_ln_Taylor_aux: { + \tex_advance:D \l_fp_count_int \c_two + \fp_mul:NNNNNN + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_input_b_decimal_int \l_fp_input_b_extended_int + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int + > \c_zero + \fp_div_integer:NNNNN + \l_fp_input_a_decimal_int \l_fp_input_a_extended_int + \l_fp_count_int + \l_fp_exp_decimal_int \l_fp_exp_extended_int + \tex_advance:D \l_fp_output_decimal_int \l_fp_exp_decimal_int + \tex_advance:D \l_fp_output_extended_int \l_fp_exp_extended_int + \tex_ifnum:D \l_fp_output_extended_int < \c_one_thousand_million + \tex_else:D + \tex_advance:D \l_fp_output_decimal_int \c_one + \tex_advance:D \l_fp_output_extended_int + -\c_one_thousand_million + \tex_fi:D + \tex_ifnum:D \l_fp_output_decimal_int < \c_one_thousand_million + \tex_else:D + \tex_advance:D \l_fp_output_integer_int \c_one + \tex_advance:D \l_fp_output_decimal_int + -\c_one_thousand_million + \tex_fi:D + \tex_expandafter:D \fp_ln_Taylor_aux: + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_pow:Nn { + \fp_pow_aux:NNn \tl_set:Nn +} +\cs_new_protected_nopar:Npn \fp_gpow:Nn { + \fp_pow_aux:NNn \tl_gset:Nn +} +\cs_generate_variant:Nn \fp_pow:Nn { c } +\cs_generate_variant:Nn \fp_gpow:Nn { c } +\cs_new_protected_nopar:Npn \fp_pow_aux:NNn #1#2#3 { + \group_begin: + \fp_read:N #2 + \l_fp_input_b_sign_int \l_fp_input_a_sign_int + \l_fp_input_b_integer_int \l_fp_input_a_integer_int + \l_fp_input_b_decimal_int \l_fp_input_a_decimal_int + \l_fp_input_b_exponent_int \l_fp_input_a_exponent_int + \fp_split:Nn a {#3} + \fp_standardise:NNNN + \l_fp_input_a_sign_int + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + \l_fp_input_a_exponent_int + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int + = \c_zero + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + = \c_zero + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_undefined_fp } + } + \tex_else:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_zero_fp } + } + \tex_fi:D + \tex_else:D + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + = \c_zero + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_one_fp } + } + \tex_else:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_pow_aux_i: + \tex_fi:D + \tex_fi:D + \fp_tmp:w #1 #2 +} +\cs_new_protected_nopar:Npn \fp_pow_aux_i: { + \tex_ifnum:D \l_fp_input_b_sign_int > \c_zero + \tl_set:Nn \l_fp_sign_tl { + } + \tex_expandafter:D \fp_pow_aux_ii: + \tex_else:D + \l_fp_input_a_extended_int \c_zero + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten + \group_begin: + \fp_extended_normalise: + \tex_ifnum:D + \etex_numexpr:D + \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int + = \c_zero + \group_end: + \tl_set:Nn \l_fp_sign_tl { - } + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_pow_aux_ii: + \tex_else:D + \group_end: + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_undefined_fp } + } + \tex_fi:D + \tex_else:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 { \c_undefined_fp } + } + \tex_fi:D + \tex_fi:D +} +\cs_new_protected_nopar:Npn \fp_pow_aux_ii: { + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \tex_expandafter:D \fp_pow_aux_iv: + \tex_else:D + \tex_ifnum:D \l_fp_input_a_exponent_int < \c_ten + \group_begin: + \l_fp_input_a_extended_int \c_zero + \fp_extended_normalise: + \tex_ifnum:D \l_fp_input_a_decimal_int = \c_zero + \tex_ifnum:D \l_fp_input_a_integer_int > \c_ten + \group_end: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_pow_aux_iv: + \tex_else:D + \group_end: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_pow_aux_iii: + \tex_fi:D + \tex_else:D + \group_end: + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \tex_expandafter:D \fp_pow_aux_iv: + \tex_fi:D + \tex_else:D + \tex_expandafter:D \tex_expandafter:D \tex_expandafter:D + \fp_pow_aux_iv: + \tex_fi:D + \tex_fi:D + \cs_set_protected_nopar:Npx \fp_tmp:w ##1##2 + { + \group_end: + ##1 ##2 + { + \l_fp_sign_tl + \int_use:N \l_fp_output_integer_int + . + \tex_expandafter:D \use_none:n + \tex_number:D \etex_numexpr:D + \l_fp_output_decimal_int + \c_one_thousand_million + \scan_stop: + e + \int_use:N \l_fp_output_exponent_int + } + } +} +\cs_new_protected_nopar:Npn \fp_pow_aux_iii: { + \l_fp_input_a_sign_int \c_one + \fp_pow_aux_iv: + \l_fp_input_a_integer_int \c_one + \l_fp_input_a_decimal_int \c_zero + \l_fp_input_a_exponent_int \c_zero + \l_fp_input_b_integer_int \l_fp_output_integer_int + \l_fp_input_b_decimal_int \l_fp_output_decimal_int + \l_fp_input_b_exponent_int \l_fp_output_exponent_int + \fp_div_internal: +} +\cs_new_protected_nopar:Npn \fp_pow_aux_iv: { + \group_begin: + \l_fp_input_a_integer_int \l_fp_input_b_integer_int + \l_fp_input_a_decimal_int \l_fp_input_b_decimal_int + \l_fp_input_a_exponent_int \l_fp_input_b_exponent_int + \fp_ln_internal: + \cs_set_protected_nopar:Npx \fp_tmp:w + { + \group_end: + \exp_not:N \l_fp_input_b_sign_int + \int_use:N \l_fp_output_sign_int \scan_stop: + \exp_not:N \l_fp_input_b_integer_int + \int_use:N \l_fp_output_integer_int \scan_stop: + \exp_not:N \l_fp_input_b_decimal_int + \int_use:N \l_fp_output_decimal_int \scan_stop: + \exp_not:N \l_fp_input_b_extended_int + \int_use:N \l_fp_output_extended_int \scan_stop: + \exp_not:N \l_fp_input_b_exponent_int + \int_use:N \l_fp_output_exponent_int \scan_stop: + } + \fp_tmp:w + \l_fp_input_a_extended_int \c_zero + \fp_mul:NNNNNNNNN + \l_fp_input_a_integer_int \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int + \l_fp_input_b_integer_int \l_fp_input_b_decimal_int + \l_fp_input_b_extended_int + \l_fp_input_a_integer_int \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int + \tex_advance:D \l_fp_input_a_exponent_int \l_fp_input_b_exponent_int + \l_fp_output_integer_int \c_zero + \l_fp_output_decimal_int \c_zero + \l_fp_output_exponent_int \c_zero + \cs_set_eq:NN \fp_exp_const:Nx \use_none:nn + \fp_exp_internal: +} +\prg_new_conditional:Npnn \fp_if_undefined:N #1 { T , F , TF , p } { \tex_ifx:D #1 \c_undefined_fp \prg_return_true: \tex_else:D \prg_return_false: \tex_fi:D } -\prg_new_conditional:Npnn \fp_if_zero:N #1 { p , T , F , TF } { +\prg_new_conditional:Npnn \fp_if_zero:N #1 { T , F , TF , p } { \tex_ifx:D #1 \c_zero_fp \prg_return_true: \tex_else:D \prg_return_false: \tex_fi:D } -\prg_new_protected_conditional:Npnn \fp_compare:nNn #1#2#3 { T , F , TF } +\prg_new_protected_conditional:Npnn \fp_compare:nNn #1#2#3 + { T , F , TF } { \group_begin: \fp_split:Nn a {#1} @@ -2076,7 +3177,8 @@ \l_fp_input_b_exponent_int \fp_compare_aux:N #2 } -\prg_new_protected_conditional:Npnn \fp_compare:NNN #1#2#3 { T , F , TF } +\prg_new_protected_conditional:Npnn \fp_compare:NNN #1#2#3 + { T , F , TF } { \group_begin: \fp_read:N #3 @@ -2265,6 +3367,21 @@ \cs_new_protected_nopar:Npn \fp_overflow_msg: { \msg_kernel_error:nn { fpu } { overflow } } +\msg_kernel_new:nnnn { fpu } { exponent-overflow } + { Number~too~big~for~exponent~unit. } + { + The~exponent~of~the~input~given~is~too~big~for~the~floating~point~ + unit:~the~maximum~input~value~for~an~exponent~is~230. + } +\cs_new_protected_nopar:Npn \fp_exp_overflow_msg: { + \msg_kernel_error:nn { fpu } { exponent-overflow } +} +\msg_kernel_new:nnnn { fpu } { logarithm-input-error } + { Invalid~input~to~ln~function. } + { Logarithms~can~only~be~calculated~for~positive~numbers. } +\cs_new_protected_nopar:Npn \fp_ln_error_msg: { + \msg_kernel_error:nn { fpu } { logarithm-input-error } +} \msg_kernel_new:nnnn { fpu } { trigonometric-overflow } { Number~too~big~for~trigonometry~unit. } { diff --git a/Master/texmf-dist/tex/latex/expl3/l3tl.sty b/Master/texmf-dist/tex/latex/expl3/l3tl.sty index 14719daf74b..cd8125b8d1b 100644 --- a/Master/texmf-dist/tex/latex/expl3/l3tl.sty +++ b/Master/texmf-dist/tex/latex/expl3/l3tl.sty @@ -48,7 +48,7 @@ %% %% ----------------------------------------------------------------------- \RequirePackage{l3names} -\GetIdInfo$Id: l3tl.dtx 2084 2010-11-17 19:12:14Z joseph $ +\GetIdInfo$Id: l3tl.dtx 2103 2010-12-18 07:40:03Z joseph $ {L3 Experimental Token Lists} \ProvidesExplPackage {\filename}{\filedate}{\fileversion}{\filedescription} @@ -235,7 +235,7 @@ \tl_set:Nn \l_tl_tmpb_tl {#2} \tex_ifx:D \l_tl_tmpa_tl \l_tl_tmpb_tl \group_end: - \prg_return_false: + \prg_return_true: \tex_else:D \group_end: \prg_return_false: -- cgit v1.2.3