diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3fp-expo.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3fp-expo.dtx | 147 |
1 files changed, 78 insertions, 69 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3fp-expo.dtx b/Master/texmf-dist/source/latex/l3kernel/l3fp-expo.dtx index fee1b90ed58..f228794e7a4 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3fp-expo.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3fp-expo.dtx @@ -36,7 +36,7 @@ % %<*driver> \RequirePackage{l3bootstrap} -\GetIdInfo$Id: l3fp-expo.dtx 4089 2012-08-14 04:52:20Z bruno $ +\GetIdInfo$Id: l3fp-expo.dtx 4151 2012-08-28 11:51:52Z bruno $ {L3 Floating-point exponential-related functions} \documentclass[full]{l3doc} \begin{document} @@ -324,7 +324,7 @@ % \begin{macrocode} \cs_new:Npn \@@_ln_x_iv:wnnnnnnnn #1; #2#3#4#5 #6#7#8#9 { - \exp_after:wN \@@_div_mantissa_pack:NNN + \exp_after:wN \@@_div_significand_pack:NNN \int_use:N \__int_eval:w \@@_ln_div_i:w #1 ; #6 #7 ; {#8} {#9} @@ -337,20 +337,20 @@ } \cs_new:Npn \@@_ln_div_i:w #1; { - \exp_after:wN \@@_div_mantissa_calc:wwnnnnnnn + \exp_after:wN \@@_div_significand_calc:wwnnnnnnn \int_use:N \__int_eval:w 999999 + 2 0000 0000 / #1 ; % Q1 } \cs_new:Npn \@@_ln_div_ii:wwn #1; #2;#3 % y; B1;B2 <- for k=1 { - \exp_after:wN \@@_div_mantissa_pack:NNN + \exp_after:wN \@@_div_significand_pack:NNN \int_use:N \__int_eval:w - \exp_after:wN \@@_div_mantissa_calc:wwnnnnnnn + \exp_after:wN \@@_div_significand_calc:wwnnnnnnn \int_use:N \__int_eval:w 999999 + #2 #3 / #1 ; % Q2 #2 #3 ; } \cs_new:Npn \@@_ln_div_vi:wwn #1; #2;#3#4#5 #6#7#8#9 %y;F1;F2F3F4x1x2x3x4 { - \exp_after:wN \@@_div_mantissa_pack:NNN + \exp_after:wN \@@_div_significand_pack:NNN \int_use:N \__int_eval:w 1000000 + #2 #3 / #1 ; % Q6 } % \end{macrocode} @@ -360,18 +360,18 @@ % result, small enough in all cases.} % \begin{quote} % \cs{@@_ln_div_after:Nw} \meta{fixed tl} -% \cs{@@_div_mantissa_pack:NNN} $10^6 + Q_{1}$ -% \cs{@@_div_mantissa_pack:NNN} $10^6 + Q_{2}$ -% \cs{@@_div_mantissa_pack:NNN} $10^6 + Q_{3}$ -% \cs{@@_div_mantissa_pack:NNN} $10^6 + Q_{4}$ -% \cs{@@_div_mantissa_pack:NNN} $10^6 + Q_{5}$ -% \cs{@@_div_mantissa_pack:NNN} $10^6 + Q_{6}$ |;| +% \cs{@@_div_significand_pack:NNN} $10^6 + Q_{1}$ +% \cs{@@_div_significand_pack:NNN} $10^6 + Q_{2}$ +% \cs{@@_div_significand_pack:NNN} $10^6 + Q_{3}$ +% \cs{@@_div_significand_pack:NNN} $10^6 + Q_{4}$ +% \cs{@@_div_significand_pack:NNN} $10^6 + Q_{5}$ +% \cs{@@_div_significand_pack:NNN} $10^6 + Q_{6}$ |;| % \meta{exponent} |;| \meta{continuation} % \end{quote} % where \meta{fixed tl} holds the logarithm of a number % in $[1,10]$, and \meta{exponent} is % the exponent. Also, the expansion is done backwards. Then -% \cs{@@_div_mantissa_pack:NNN} puts things in the +% \cs{@@_div_significand_pack:NNN} puts things in the % correct order to add the $Q_{i}$ together and put semicolons % between each piece. Once those have been expanded, we get % \begin{quote} @@ -491,7 +491,7 @@ \@@_ln_Taylor_break:w \fi: \exp_after:wN \@@_fixed_div_int:wwN \c_@@_one_fixed_tl ; #1; - \@@_fixed_add:wwN #2; + \@@_fixed_add:wwn #2; \@@_fixed_mul:wwn #3; { \exp_after:wN \@@_ln_Taylor_loop:www @@ -499,7 +499,7 @@ } #3; } -\cs_new:Npn \@@_ln_Taylor_break:w \fi: #1 \@@_fixed_add:wwN #2#3; #4 ;; +\cs_new:Npn \@@_ln_Taylor_break:w \fi: #1 \@@_fixed_add:wwn #2#3; #4 ;; { \fi: \exp_after:wN \@@_fixed_mul:wwn @@ -527,9 +527,9 @@ \cs_new:Npn \@@_ln_c:NwNw #1 #2; #3 { \if_meaning:w + #1 - \exp_after:wN \exp_after:wN \exp_after:wN \@@_fixed_sub:wwN + \exp_after:wN \exp_after:wN \exp_after:wN \@@_fixed_sub:wwn \else: - \exp_after:wN \exp_after:wN \exp_after:wN \@@_fixed_add:wwN + \exp_after:wN \exp_after:wN \exp_after:wN \@@_fixed_add:wwn \fi: #3 ; #2 ; } @@ -564,11 +564,11 @@ \if_int_compare:w #2 > \c_zero \exp_after:wN \@@_ln_exponent_small:NNww \exp_after:wN 0 - \exp_after:wN \@@_fixed_sub:wwN \__int_value:w + \exp_after:wN \@@_fixed_sub:wwn \__int_value:w \else: \exp_after:wN \@@_ln_exponent_small:NNww \exp_after:wN 2 - \exp_after:wN \@@_fixed_add:wwN \__int_value:w - + \exp_after:wN \@@_fixed_add:wwn \__int_value:w - \fi: \fi: #2; #1; @@ -580,7 +580,7 @@ \cs_new:Npn \@@_ln_exponent_one:ww 1; #1; { \c_zero - \exp_after:wN \@@_fixed_sub:wwN \c_@@_ln_x_fixed_tl ; #1; + \exp_after:wN \@@_fixed_sub:wwn \c_@@_ln_x_fixed_tl ; #1; \@@_fixed_to_float:wN 0 } % \end{macrocode} @@ -673,7 +673,7 @@ } #5 {#4} - #2 0 + #1 #2 0 \tex_romannumeral:D \fi: \fi: @@ -693,8 +693,9 @@ % delimited by a semicolon, form a fixed point number, so we pack it % in blocks of $4$ digits. % \begin{macrocode} -\cs_new:Npn \@@_exp_Taylor:Nnnwn #1#2#3 #4; #5 +\cs_new:Npn \@@_exp_Taylor:Nnnwn #1#2#3 #4; #5 #6 { + #6 \@@_pack_twice_four:wNNNNNNNN \@@_pack_twice_four:wNNNNNNNN \@@_pack_twice_four:wNNNNNNNN @@ -749,7 +750,7 @@ % stream (we are currently within an \cs{__int_eval:w}), and keeping % track of a fixed point number, |#1| for the numbered auxiliaries. % Our usage of \cs{if_case:w} is somewhat dirty for optimization: -% \TeX{} jumps to the appropriate case, but we then lose the +% \TeX{} jumps to the appropriate case, but we then close the % \cs{if_case:w} \enquote{by hand}, using \cs{or:} and \cs{fi:} as % delimiters. % \begin{macrocode} @@ -860,9 +861,9 @@ #1; \@@_exp_large_after:wwn } -\cs_new:Npn \@@_exp_large_after:wwn #1; #2; +\cs_new:Npn \@@_exp_large_after:wwn #1; #2; #3 { - \@@_exp_Taylor:Nnnwn ? { } { } 0 #2; {} + \@@_exp_Taylor:Nnnwn ? { } { } 0 #2; {} #3 \@@_fixed_mul:wwn #1; } % \end{macrocode} @@ -942,10 +943,12 @@ % \begin{macro}[aux, EXP]{\@@_pow_zero_or_inf:ww} % Raising $-0$ or $-\infty$ to \texttt{nan} yields \texttt{nan}. For % other powers, the result is $+0$ if $0$ is raised to a positive -% power or $\infty$ to a negative power, and $+\infty$ otherwise. We -% can thus know the result by comparing the type of $a$ with the sign -% of $b$, since those conveniently take the same possible values, $0$ -% and~$2$. +% power or $\infty$ to a negative power, and $+\infty$ otherwise. +% Thus, if the type of $a$ and the sign of $b$ coincide, the result +% is~$0$, since those conveniently take the same possible values, $0$ +% and~$2$. Otherwise, either $a=\pm 0$ with $b<0$ and we have a +% division by zero, or $a=\pm\infty$ and $b>0$ and the result is also +% $+\infty$, but without any exception. % \begin{macrocode} \cs_new:Npn \@@_pow_zero_or_inf:ww \s_@@ \@@_chk:w #1#2; \s_@@ \@@_chk:w #3#4 { @@ -954,6 +957,13 @@ \fi: \if_meaning:w #1 #4 \@@_case_return_o:Nw \c_zero_fp + \fi: + \if_meaning:w 0 #1 + \@@_case_use:nw + { + \@@_division_by_zero_o:NNww \c_inf_fp ^ + \s_@@ \@@_chk:w #1 #2 ; + } \else: \@@_case_return_o:Nw \c_inf_fp \fi: @@ -986,7 +996,7 @@ \fi: \@@_case_return_o:Nww \c_one_fp \fi: - \if_case:w #4 ~ + \if_case:w #4 \exp_stop_f: \or: \exp_after:wN \@@_pow_npos:Nww \exp_after:wN #5 @@ -1028,11 +1038,12 @@ \exp_after:wN 0 \__int_value:w \if:w #1 \if_int_compare:w #3 > \c_zero 0 \else: 2 \fi: - \exp_after:wN \@@_pow_npos_aux:Nnww + \exp_after:wN \@@_pow_npos_aux:NNnww + \exp_after:wN + \exp_after:wN \@@_fixed_to_float:wN \else: - - - \exp_after:wN \@@_pow_npos_aux:Nnww + \exp_after:wN \@@_pow_npos_aux:NNnww + \exp_after:wN - \exp_after:wN \@@_fixed_inv_to_float:wN \fi: {#3} @@ -1041,46 +1052,52 @@ % \end{macro} % %^^A begin[todo] -% \begin{macro}[aux, EXP]{\@@_pow_npos_aux:Nnww} +% \begin{macro}[aux, EXP]{\@@_pow_npos_aux:NNnww} % The first argument is the conversion function from fixed point to % float. Then comes an exponent and the $4$ brace groups of $x$, % followed by $b$. Compute $-\ln(x)$. % \begin{macrocode} -\cs_new:Npn \@@_pow_npos_aux:Nnww #1#2#3#4; \s_@@ \@@_chk:w 1#5#6#7; +\cs_new:Npn \@@_pow_npos_aux:NNnww #1#2#3#4#5; \s_@@ \@@_chk:w 1#6#7#8; { + #1 \__int_eval:w - \@@_ln_significand:NNNNnnnN #3#4 - \@@_pow_exponent:wnN {#2} - \@@_fixed_mul:wwn #7 {0000}{0000} ; - \@@_pow_B:wwN #6; - #1 0 % fixed_to_float:wN + \@@_ln_significand:NNNNnnnN #4#5 + \@@_pow_exponent:wnN {#3} + \@@_fixed_mul:wwn #8 {0000}{0000} ; + \@@_pow_B:wwN #7; + #1 #2 0 % fixed_to_float:wN } \cs_new:Npn \@@_pow_exponent:wnN #1; #2 { \if_int_compare:w #2 > \c_zero - \exp_after:wN \@@_pow_exponent:Nwnnnnnn % n\ln(10) - (-\ln(x)) + \exp_after:wN \@@_pow_exponent:Nwnnnnnwn % n\ln(10) - (-\ln(x)) \exp_after:wN + \else: - \exp_after:wN \@@_pow_exponent:Nwnnnnnn % -( |n|\ln(10) + (-\ln(x)) ) + \exp_after:wN \@@_pow_exponent:Nwnnnnnwn % -( |n|\ln(10) + (-\ln(x)) ) \exp_after:wN - \fi: #2; #1; } -\cs_new:Npn \@@_pow_exponent:Nwnnnnnn #1#2; #3#4#5#6#7#8; - { %^^A todo: use that in ln. %^^A todo: log(1.00...) too inaccurate? - \exp_after:wN \@@_fixed_mul_after:wwn - \int_use:N \__int_eval:w -5 0000 - \exp_after:wN \@@_fixed_mul_pack:NNNNNw - \int_use:N \__int_eval:w 4 9995 0000 #1#2*23025 - #1 #3 - \exp_after:wN \@@_fixed_mul_pack:NNNNNw - \int_use:N \__int_eval:w 4 9995 0000 #1 #2*8509 - #1 #4 - \exp_after:wN \@@_fixed_mul_pack:NNNNNw - \int_use:N \__int_eval:w 4 9995 0000 #1 #2*2994 - #1 #5 - \exp_after:wN \@@_fixed_mul_pack:NNNNNw - \int_use:N \__int_eval:w 4 9995 0000 #1 #2*0456 - #1 #6 - \exp_after:wN \@@_fixed_mul_pack:NNNNNw - \int_use:N \__int_eval:w 5 0000 0000 #1 #2*8401 - #1 #7 - #1 ( #2*7991 - #8 ) / 1 0000 ; ; +\cs_new:Npn \@@_pow_exponent:Nwnnnnnwn #1#2; #3#4#5#6#7#8; #9 + { %^^A todo: use that in ln. + \exp_after:wN \@@_fixed_mul_after:wn + \int_use:N \__int_eval:w \c_@@_leading_shift_int + \exp_after:wN \@@_pack:NNNNNwn + \int_use:N \__int_eval:w \c_@@_middle_shift_int + #1#2*23025 - #1 #3 + \exp_after:wN \@@_pack:NNNNNwn + \int_use:N \__int_eval:w \c_@@_middle_shift_int + #1 #2*8509 - #1 #4 + \exp_after:wN \@@_pack:NNNNNwn + \int_use:N \__int_eval:w \c_@@_middle_shift_int + #1 #2*2994 - #1 #5 + \exp_after:wN \@@_pack:NNNNNwn + \int_use:N \__int_eval:w \c_@@_middle_shift_int + #1 #2*0456 - #1 #6 + \exp_after:wN \@@_pack:NNNNNwn + \int_use:N \__int_eval:w \c_@@_trailing_shift_int + #1 #2*8401 - #1 #7 + #1 ( #2*7991 - #8 ) / 1 0000 ; {#9} ; } \cs_new:Npn \@@_pow_B:wwN #1#2#3#4#5#6; #7; { @@ -1097,7 +1114,7 @@ \int_use:N \__int_eval:w 10 0000 + #1 \__int_eval_end: #2#3#4#5#6 0000 0000 0000 0000 0000 0000 ; %^^A todo: how many 0? } -\cs_new:Npn \@@_pow_C_overflow:w #1; #2; +\cs_new:Npn \@@_pow_C_overflow:w #1; #2; #3 { + \c_two * \c_@@_max_exponent_int \exp_after:wN \@@_fixed_continue:wn \c_@@_one_fixed_tl ; @@ -1129,11 +1146,11 @@ % \end{macro} %^^A end[todo] % -% \begin{macro}[aux, EXP]{\@@_pow_neg:www, \@@_pow_neg_neg:w} +% \begin{macro}[aux, EXP]{\@@_pow_neg:www} % This function is followed by three floating point numbers: $|a|^b$, % $a\in[-\infty,-0]$, and $b$. If $b$ is an even integer (case $-1$), % $a^b=|a|^b$. If $b$ is an odd integer (case $0$), $a^b=-|a|^b$, -% obtained by a call to \cs{@@_pow_neg_neg:w}. Otherwise, the sign is +% obtained by a call to \cs{@@_neg_o:w}. Otherwise, the sign is % undefined. This is invalid, unless $|a|^b$ turns out to be $+0$ or % \texttt{nan}, in which case we return that as $a^b$. In particular, % since the underflow detection occurs before \cs{@@_pow_neg:www} is @@ -1143,7 +1160,7 @@ \cs_new:Npn \@@_pow_neg:www \s_@@ \@@_chk:w #1#2; #3; #4; { \if_case:w \@@_pow_neg_case:w #4 ; - \exp_after:wN \@@_pow_neg_neg:w + \exp_after:wN \@@_neg_o:w \or: \if_int_compare:w \__int_eval:w #1 / \c_two = \c_one \@@_invalid_operation_o:Nww ^ #3; #4; @@ -1155,14 +1172,6 @@ \@@_exp_after_o:w \s_@@ \@@_chk:w #1#2; } -\cs_new:Npn \@@_pow_neg_neg:w \@@_exp_after_o:w \s_@@ \@@_chk:w #1#2 - { - \exp_after:wN \@@_exp_after_o:w - \exp_after:wN \s_@@ - \exp_after:wN \@@_chk:w - \exp_after:wN #1 - \int_use:N \__int_eval:w \c_two - #2 \__int_eval_end: - } % \end{macrocode} % \end{macro} % |