diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3kernel/l3fp.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/l3kernel/l3fp.sty | 573 |
1 files changed, 430 insertions, 143 deletions
diff --git a/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty b/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty index 679f97c2519..b304cbda2d0 100644 --- a/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty +++ b/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty @@ -59,7 +59,7 @@ %% ----------------------------------------------------------------------- %% \RequirePackage{l3bootstrap} -\GetIdInfo$Id: l3fp.dtx 4601 2013-11-18 23:13:28Z bruno $ +\GetIdInfo$Id: l3fp.dtx 4633 2013-12-31 17:28:46Z joseph $ {L3 Floating points} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} @@ -99,7 +99,6 @@ %% \cs_new:Npn \__fp_use_none_stop_f:n #1 { \exp_stop_f: } \cs_new:Npn \__fp_use_s:n #1 { #1; } -\cs_new:Npn \__fp_use_braced_s:n #1 { {#1} ; } \cs_new:Npn \__fp_use_s:nn #1#2 { #1#2; } \cs_new:Npn \__fp_use_none_until_s:w #1; { } \cs_new:Npn \__fp_use_i_until_s:nw #1#2; {#1} @@ -107,6 +106,7 @@ \cs_new:Npn \__fp_reverse_args:Nww #1 #2; #3; { #1 #3; #2; } \cs_new:Npn \__fp_rrot:www #1; #2; #3; { #2; #3; #1; } \cs_new:Npn \__fp_use_i:ww #1; #2; { #1; } +\cs_new:Npn \__fp_use_i:www #1; #2; #3; { #1; } \__scan_new:N \s__fp \cs_new_protected:Npn \__fp_chk:w #1 ; { @@ -228,15 +228,11 @@ \int_const:Nn \c__fp_middle_shift_int { 5 0000 * 9999 } \int_const:Nn \c__fp_trailing_shift_int { 5 0000 * 10000 } \cs_new:Npn \__fp_pack:NNNNNw #1 #2#3#4#5 #6; { + #1#2#3#4#5 ; {#6} } -\cs_new:Npn \__fp_pack:NNNNNwn #1 #2#3#4#5 #6; #7 - { + #1#2#3#4#5 ; {#7} {#6} } \int_const:Nn \c__fp_big_leading_shift_int { - 15 2374 } \int_const:Nn \c__fp_big_middle_shift_int { 15 2374 * 9999 } \int_const:Nn \c__fp_big_trailing_shift_int { 15 2374 * 10000 } \cs_new:Npn \__fp_pack_big:NNNNNNw #1#2 #3#4#5#6 #7; { + #1#2#3#4#5#6 ; {#7} } -\cs_new:Npn \__fp_pack_big:NNNNNNwn #1#2 #3#4#5#6 #7; #8 - { + #1#2#3#4#5#6 ; {#8} {#7} } \int_const:Nn \c__fp_Bigg_leading_shift_int { - 20 0000 } \int_const:Nn \c__fp_Bigg_middle_shift_int { 20 0000 * 9999 } \int_const:Nn \c__fp_Bigg_trailing_shift_int { 20 0000 * 10000 } @@ -304,38 +300,45 @@ { \fi: \__fp_exp_after_o:w \s__fp #3 ; } \cs_new:Npn \__fp_case_return_ii_o:ww #1 \fi: #2 \s__fp #3 ; { \fi: \__fp_exp_after_o:w } -\cs_new:Npn \__fp_small_int:wTF \s__fp \__fp_chk:w #1 +\cs_new:Npn \__fp_small_int:wTF \s__fp \__fp_chk:w #1#2 { \if_case:w #1 \exp_stop_f: \__fp_case_return:nw { \__fp_small_int_true:wTF 0 ; } \or: \exp_after:wN \__fp_small_int_normal:NnwTF + \or: + \__fp_case_return:nw + { + \exp_after:wN \__fp_small_int_true:wTF \__int_value:w + \if_meaning:w 2 #2 - \fi: 1 0000 0000 ; + } \else: \__fp_case_return:nw \use_ii:nn \fi: + #2 } \cs_new:Npn \__fp_small_int_true:wTF #1; #2#3 { #2 {#1} } \cs_new:Npn \__fp_small_int_normal:NnwTF #1#2#3; { \if_int_compare:w #2 > \c_zero - \if_int_compare:w #2 > \c_eight - \exp_after:wN \exp_after:wN - \exp_after:wN \use_iii:nnn - \else: - \__fp_decimate:nNnnnn { \c_sixteen - #2 } - \__fp_small_int_test:NnnwNTF - #3 #1 - \fi: + \__fp_decimate:nNnnnn { \c_sixteen - #2 } + \__fp_small_int_test:NnnwNnw + #3 #1 {#2} \else: \exp_after:wN \use_iii:nnn \fi: ; } -\cs_new:Npn \__fp_small_int_test:NnnwNTF #1#2#3#4; #5 +\cs_new:Npn \__fp_small_int_test:NnnwNnw #1#2#3#4; #5#6 { \if_meaning:w 0 #1 \exp_after:wN \__fp_small_int_true:wTF - \__int_value:w \if_meaning:w 2 #5 - \fi: #3 + \__int_value:w \if_meaning:w 2 #5 - \fi: + \if_int_compare:w #6 > \c_eight + 1 0000 0000 + \else: + #3 + \fi: \else: - \exp_after:wN \use_i:nn + \use_i:nn \fi: } \cs_new:Npn \__fp_array_count:n #1 @@ -458,10 +461,10 @@ \exp_after:wN \c_nan_fp } \exp_args:Nno \use:n - { \cs_set:Npn \__fp_invalid_operation_tl_o:nf ##1##2 } + { \cs_set:Npn \__fp_invalid_operation_tl_o:ff ##1##2 } { #1 - \__fp_error:nnfn { invalid } {##1} {##2} { } + \__fp_error:nffn { invalid } {##1} {##2} { } \fp_flag_on:n { invalid_operation } \exp_after:wN \c_nan_fp } @@ -525,7 +528,7 @@ } \cs_new:Npn \__fp_invalid_operation:nnw #1#2#3; { } \cs_new:Npn \__fp_invalid_operation_o:Nww #1#2; #3; { } -\cs_new:Npn \__fp_invalid_operation_tl_o:nf #1 #2 { } +\cs_new:Npn \__fp_invalid_operation_tl_o:ff #1 #2 { } \cs_new:Npn \__fp_division_by_zero_o:Nnw #1#2#3; { } \cs_new:Npn \__fp_division_by_zero_o:NNww #1#2#3; #4; { } \cs_new:Npn \__fp_overflow:w { } @@ -697,12 +700,37 @@ } \cs_new_eq:NN \__fp_round_to_nearest_neg:NNN \__fp_round_to_nearest:NNN \cs_new_eq:NN \__fp_round_neg:NNN \__fp_round_to_nearest_neg:NNN +\cs_new:Npn \__fp_round_o:Nw #1#2 @ + { + \if_case:w + \__int_eval:w \__fp_array_count:n {#2} - \c_one \__int_eval_end: + \__fp_round:Nwn #1 #2 {0} \tex_romannumeral:D + \or: \__fp_round:Nww #1 #2 \tex_romannumeral:D + \else: + \__fp_error:nffn { num-args } + { \__fp_round_name_from_cs:N #1 () } { 1 } { 2 } + \exp_after:wN \c_nan_fp \tex_romannumeral:D + \fi: + -`0 + } +\cs_new:Npn \__fp_round_name_from_cs:N #1 + { + \cs_if_eq:NNTF #1 \__fp_round_to_zero:NNN { trunc } + { + \cs_if_eq:NNTF #1 \__fp_round_to_ninf:NNN { floor } + { + \cs_if_eq:NNTF #1 \__fp_round_to_pinf:NNN { ceil } + { round } + } + } + } \cs_new:Npn \__fp_round:Nww #1#2 ; #3 ; { \__fp_small_int:wTF #3; { \__fp_round:Nwn #1#2; } { - \__fp_invalid_operation_tl_o:nf - { round } { \__fp_array_to_clist:n { #2; #3; } } + \__fp_invalid_operation_tl_o:ff + { \__fp_round_name_from_cs:N #1 } + { \__fp_array_to_clist:n { #2; #3; } } } } \cs_new:Npn \__fp_round:Nwn #1 \s__fp \__fp_chk:w #2#3#4; #5 @@ -1384,7 +1412,7 @@ \exp_after:wN \__fp_parse_apply_unary:NNNwN \exp_after:wN ##1 \exp_after:wN #4 - \cs:w __fp_#3_o:w \exp_after:wN \cs_end: + \exp_after:wN #3 \tex_romannumeral:D \if_int_compare:w #2 < ##1 \__fp_parse_operand:Nw ##1 @@ -1394,8 +1422,8 @@ \__fp_parse_expand:w } } -\__fp_tmp:w - \c_twelve { set_sign } 2 -\__fp_tmp:w ! \c_twelve { not } ? +\__fp_tmp:w - \c_twelve \__fp_set_sign_o:w 2 +\__fp_tmp:w ! \c_twelve \__fp_not_o:w ? \cs_new:cpn { __fp_parse_prefix_.:Nw } #1 { \exp_after:wN \__fp_parse_infix_after_operand:NwN @@ -1511,6 +1539,8 @@ { \__fp_parse_unary_function:nNN {exp} ? } \cs_new_nopar:Npn \__fp_parse_word_ln:N { \__fp_parse_unary_function:nNN {ln} ? } +\cs_new_nopar:Npn \__fp_parse_word_sqrt:N + { \__fp_parse_unary_function:nNN {sqrt} ? } \tl_map_inline:nn { {acos} {acsc} {asec} {asin} @@ -1522,6 +1552,12 @@ \cs_new_nopar:cpn { __fp_parse_word_#1d:N } { \__fp_parse_unary_function:nNN {#1} \use_ii:nn } } +\cs_new_nopar:Npn \__fp_parse_word_trunc:N + { \__fp_parse_function:NNN \__fp_round_o:Nw \__fp_round_to_zero:NNN } +\cs_new_nopar:Npn \__fp_parse_word_floor:N + { \__fp_parse_function:NNN \__fp_round_o:Nw \__fp_round_to_ninf:NNN } +\cs_new_nopar:Npn \__fp_parse_word_ceil:N + { \__fp_parse_function:NNN \__fp_round_o:Nw \__fp_round_to_pinf:NNN } \cs_new:Npn \__fp_parse_word_round:N #1#2 { \if_meaning:w + #2 @@ -1535,27 +1571,12 @@ \fi: \fi: \fi: - \exp_after:wN \__fp_parse_apply_round:NNwN - \exp_after:wN #1 - \exp_after:wN \__fp_round_to_nearest:NNN - \tex_romannumeral:D - \__fp_parse_operand:Nw \c_sixteen \__fp_parse_expand:w #2 + \__fp_parse_function:NNN + \__fp_round_o:Nw \__fp_round_to_nearest:NNN #1 + #2 } \cs_new:Npn \__fp_parse_round:Nw - #1 #2 \__fp_round_to_nearest:NNN #3 \__fp_parse_expand:w #4 - { #2 #1 #3 \__fp_parse_expand:w } -\cs_new:Npn \__fp_parse_apply_round:NNwN #1#2#3@#4 - { - \if_case:w \__int_eval:w \__fp_array_count:n {#3} - \c_one \__int_eval_end: - \__fp_round:Nwn #2 #3 {0} \tex_romannumeral:D - \or: \__fp_round:Nww #2 #3 \tex_romannumeral:D - \else: - \__msg_kernel_expandable_error:nnnnn - { kernel } { fp-num-args } { round() } { 1 } { 2 } - \exp_after:wN \c_nan_fp \tex_romannumeral:D - \fi: - -`0 #4 #1 - } + #1 #2 \__fp_round_to_nearest:NNN #3#4 { #2 #1 #3 } \cs_new:Npn \__fp_parse:n #1 { \tex_romannumeral:D @@ -1821,63 +1842,63 @@ \group_end: \cs_new:cpn { __fp_parse_infix_<:N } #1 { - \__fp_infix_compare:N #1 \c_one_fp - \c_zero_fp \c_zero_fp \c_zero_fp \c_zero_fp < + \__fp_parse_compare:NNNNNNN #1 \c_one + \c_zero \c_zero \c_zero \c_zero < } \cs_new:cpn { __fp_parse_infix_=:N } #1 { - \__fp_infix_compare:N #1 \c_one_fp - \c_zero_fp \c_zero_fp \c_zero_fp \c_zero_fp = + \__fp_parse_compare:NNNNNNN #1 \c_one + \c_zero \c_zero \c_zero \c_zero = } \cs_new:cpn { __fp_parse_infix_>:N } #1 { - \__fp_infix_compare:N #1 \c_one_fp - \c_zero_fp \c_zero_fp \c_zero_fp \c_zero_fp > + \__fp_parse_compare:NNNNNNN #1 \c_one + \c_zero \c_zero \c_zero \c_zero > } \cs_new:cpn { __fp_parse_infix_!:N } #1 { - \exp_after:wN \__fp_parse_infix_excl_aux:NN - \exp_after:wN #1 \tex_romannumeral:D \__fp_parse_expand:w - } -\cs_new:Npn \__fp_parse_infix_excl_aux:NN #1#2 - { - \__fp_infix_compare:N #1 \c_zero_fp - \c_one_fp \c_one_fp \c_one_fp \c_one_fp #2 + \exp_after:wN \__fp_parse_compare:NNNNNNN + \exp_after:wN #1 + \exp_after:wN \c_zero + \exp_after:wN \c_one + \exp_after:wN \c_one + \exp_after:wN \c_one + \exp_after:wN \c_one } -\cs_new:Npn \__fp_parse_infix_excl_error: +\cs_new:Npn \__fp_parse_excl_error: { \__msg_kernel_expandable_error:nnnn { kernel } { fp-missing } { = } { ~after~!. } } -\cs_new:Npn \__fp_infix_compare:N #1 +\cs_new:Npn \__fp_parse_compare:NNNNNNN #1 { \if_int_compare:w #1 < \c_seven - \exp_after:wN \__fp_parse_compare:NNNNNNw - \exp_after:wN \__fp_parse_infix_excl_error: + \exp_after:wN \__fp_parse_compare_auxi:NNNNNNN + \exp_after:wN \__fp_parse_excl_error: \else: \exp_after:wN @ \exp_after:wN \use_none:n - \exp_after:wN \__fp_infix_compare:N + \exp_after:wN \__fp_parse_compare:NNNNNNN \fi: } -\cs_new:Npn \__fp_parse_compare:NNNNNNw #1#2#3#4#5#6#7 +\cs_new:Npn \__fp_parse_compare_auxi:NNNNNNN #1#2#3#4#5#6#7 { \if_case:w - \if_catcode:w \scan_stop: #7 + \if_catcode:w \scan_stop: \exp_not:N #7 \c_minus_one \else: \__int_eval:w `#7 - `< \__int_eval_end: \fi: - \__fp_parse_compare_expand:NNNNNw #2#2#4#5#6 - \or: \__fp_parse_compare_expand:NNNNNw #2#3#2#5#6 - \or: \__fp_parse_compare_expand:NNNNNw #2#3#4#2#6 - \or: \__fp_parse_compare_expand:NNNNNw #2#3#4#5#2 - \else: #1 \__fp_parse_compare_end:NNNN #3#4#5#6#7 + \__fp_parse_compare_auxii:NNNNN #2#2#4#5#6 + \or: \__fp_parse_compare_auxii:NNNNN #2#3#2#5#6 + \or: \__fp_parse_compare_auxii:NNNNN #2#3#4#2#6 + \or: \__fp_parse_compare_auxii:NNNNN #2#3#4#5#2 + \else: #1 \__fp_parse_compare_end:NNNNw #3#4#5#6#7 \fi: } -\cs_new:Npn \__fp_parse_compare_expand:NNNNNw #1#2#3#4#5 +\cs_new:Npn \__fp_parse_compare_auxii:NNNNN #1#2#3#4#5 { - \exp_after:wN \__fp_parse_compare:NNNNNNw + \exp_after:wN \__fp_parse_compare_auxi:NNNNNNN \exp_after:wN \prg_do_nothing: \exp_after:wN #1 \exp_after:wN #2 @@ -1886,11 +1907,12 @@ \exp_after:wN #5 \tex_romannumeral:D \exp_after:wN \__fp_parse_expand:w } -\cs_new:Npn \__fp_parse_compare_end:NNNN #1#2#3#4#5 \fi: +\cs_new:Npn \__fp_parse_compare_end:NNNNw #1#2#3#4#5 \fi: { \fi: \exp_after:wN @ - \exp_after:wN \__fp_parse_apply_compare:NwNNNNwN + \exp_after:wN \__fp_parse_apply_compare:NwNNNNNwN + \exp_after:wN \c_one_fp \exp_after:wN #1 \exp_after:wN #2 \exp_after:wN #3 @@ -1898,22 +1920,107 @@ \tex_romannumeral:D \__fp_parse_operand:Nw \c_seven \__fp_parse_expand:w #5 } -\cs_new:Npn \__fp_parse_apply_compare:NwNNNNwN #1 #2@ #3#4#5#6 #7@ #8 +\cs_new:Npn \__fp_parse_apply_compare:NwNNNNNwN + #1 #2@ #3 #4#5#6#7 #8@ #9 { - \exp_after:wN \__fp_parse_continue:NwN - \exp_after:wN #1 - \tex_romannumeral:D -`0 - \exp_after:wN \exp_after:wN - \exp_after:wN \exp_after:wN - \exp_after:wN \exp_after:wN - \if_case:w \__fp_compare_back:ww #7 #2 \exp_stop_f: - #4 - \or: #5 - \or: #6 - \else: #3 - \fi: - \tex_romannumeral:D -`0 #8 #1 + \if_int_odd:w + \if_meaning:w \c_zero_fp #3 + \c_zero + \else: + \if_case:w \__fp_compare_back:ww #8 #2 \exp_stop_f: + #5 \or: #6 \or: #7 \else: #4 + \fi: + \fi: + \exp_after:wN \__fp_parse_apply_compare_aux:NNwN + \exp_after:wN \c_one_fp + \else: + \exp_after:wN \__fp_parse_apply_compare_aux:NNwN + \exp_after:wN \c_zero_fp + \fi: + #1 #8 #9 + } +\cs_new:Npn \__fp_parse_apply_compare_aux:NNwN #1 #2 #3; #4 + { + \if_meaning:w \__fp_parse_compare:NNNNNNN #4 + \exp_after:wN \__fp_parse_continue_compare:NNwNN + \exp_after:wN #1 + \exp_after:wN #2 + \tex_romannumeral:D -`0 + \__fp_exp_after_o:w #3; + \tex_romannumeral:D -`0 + \else: + \exp_after:wN \__fp_parse_continue:NwN + \exp_after:wN #2 + \tex_romannumeral:D -`0 + \exp_after:wN #1 + \tex_romannumeral:D -`0 + \fi: + #4 #2 + } +\cs_new:Npn \__fp_parse_continue_compare:NNwNN #1#2 #3@ #4#5 + { #4 #2 #3@ #1 } +\group_begin: + \char_set_catcode_other:N \^^@ + \cs_new:Npn \fp_function:Nw #1 { ^^@ ; { \exp_after:wN #1 } } +\group_end: +\group_begin: + \char_set_catcode_other:N \^^@ + \cs_new_protected:Npn \fp_new_function:Npn #1#2# + { + \cs_new:Npx #1 + { + ^^@ ; + { + \exp_not:N \exp_after:wN + \exp_not:N \__fp_function_args:Nwn + \exp_not:N \exp_after:wN + \exp_not:c { __fp_user_ \cs_to_str:N #1 } + \exp_not:N \__int_value:w + \int_eval:n { \tl_count:n {#2} / \c_two } + \exp_not:N \exp_after:wN ; + } + } + \cs_new:cpn { __fp_user_ \cs_to_str:N #1 } #2 + } +\group_end: +\cs_new:Npn \__fp_function_args:Nwn #1#2; #3 + { + \int_compare:nNnTF { \tl_count:n {#3} } = {#2} + { #1 #3 } + { + \__msg_kernel_expandable_error:nnnnn + { kernel } { fp-num-args } { #1() } {#2} {#2} + \c_nan_fp + } + } +\group_begin: + \char_set_catcode_other:N \^^@ + \cs_new:cpn { __fp_parse_prefix_ ^^@ :Nw } #1 ; #2 + { + \exp_after:wN \__fp_function_apply:NnwN + \exp_after:wN #1 + \exp_after:wN { #2 \exp_after:wN } + \tex_romannumeral:D + \__fp_parse_operand:Nw \c_sixteen \__fp_parse_expand:w + } +\group_end: +\cs_new:Npn \__fp_function_apply:NnwN #1#2#3@#4 + { + \exp_after:wN \__fp_exp_after_array_f:w + \tex_romannumeral:D -`0 + \__fp_function_store:wwNwnn #3 + \s__fp_mark \__fp_function_store:wwNwnn ; + \s__fp_mark \__fp_function_store_end:wnnn + \s__fp_stop { } { } {#2} + \s__fp_stop + #4 #1 } +\cs_new:Npn \__fp_function_store:wwNwnn + #1; #2 \s__fp_mark #3#4 \s__fp_stop #5#6 + { #3 #2 \s__fp_mark #3#4 \s__fp_stop { #5 #6 } { { #1; } } } +\cs_new:Npn \__fp_function_store_end:wnnn + #1 \s__fp_stop #2#3#4 + { \__fp_parse:n { #4 {#2} } } \__msg_kernel_new:nnn { kernel } { unknown-fp-word } { Unknown~fp~word~#1. } \__msg_kernel_new:nnn { kernel } { fp-missing } @@ -2250,12 +2357,7 @@ %% ----------------------------------------------------------------------- %% \cs_new:Npn \__fp_basics_pack_low:NNNNNw #1 #2#3#4#5 #6; - { - \if_meaning:w 2 #1 - + \c_one - \fi: - ; {#2#3#4#5} {#6} ; - } + { + #1 - \c_one ; {#2#3#4#5} {#6} ; } \cs_new:Npn \__fp_basics_pack_high:NNNNNw #1 #2#3#4#5 #6; { \if_meaning:w 2 #1 @@ -2824,6 +2926,193 @@ \__int_value:w \__fp_round_digit:Nw #7 #8 ; \exp_after:wN ; } +\cs_new:Npn \__fp_sqrt_o:w #1 \s__fp \__fp_chk:w #2#3#4; @ + { + \if_meaning:w 0 #2 \__fp_case_return_same_o:w \fi: + \if_meaning:w 2 #3 + \__fp_case_use:nw { \__fp_invalid_operation_o:nw { sqrt } } + \fi: + \if_meaning:w 1 #2 \else: \__fp_case_return_same_o:w \fi: + \__fp_sqrt_npos_o:w + \s__fp \__fp_chk:w #2 #3 #4; + } +\cs_new:Npn \__fp_sqrt_npos_o:w \s__fp \__fp_chk:w 1 0 #1#2#3#4#5; + { + \exp_after:wN \__fp_sanitize:Nw + \exp_after:wN 0 + \int_use:N \__int_eval:w + \if_int_odd:w #1 \exp_stop_f: + \exp_after:wN \__fp_sqrt_npos_auxi_o:wwnnN + \fi: + #1 / \c_two + \__fp_sqrt_Newton_o:wwn 56234133; 0; {#2#3} {#4#5} 0 + } +\cs_new:Npn \__fp_sqrt_npos_auxi_o:wwnnN #1 / \c_two #2; 0; #3#4#5 + { + ( #1 + \c_one ) / \c_two + \__fp_pack_eight:wNNNNNNNN + \__fp_sqrt_npos_auxii_o:wNNNNNNNN + ; + 0 #3 #4 + } +\cs_new:Npn \__fp_sqrt_npos_auxii_o:wNNNNNNNN #1; #2#3#4#5#6#7#8#9 + { \__fp_sqrt_Newton_o:wwn 17782794; 0; {#1} {#2#3#4#5#6#7#8#9} } +\cs_new:Npn \__fp_sqrt_Newton_o:wwn #1; #2; #3 + { + \if_int_compare:w #1 = #2 \exp_stop_f: + \exp_after:wN \__fp_sqrt_auxi_o:NNNNwnnN + \int_use:N \__int_eval:w 9999 9999 + + \exp_after:wN \__fp_use_none_until_s:w + \fi: + \exp_after:wN \__fp_sqrt_Newton_o:wwn + \int_use:N \__int_eval:w (#1 + #3 * 1 0000 0000 / #1) / \c_two ; + #1; {#3} + } +\cs_new:Npn \__fp_sqrt_auxi_o:NNNNwnnN 1 #1#2#3#4#5; + { + \__fp_sqrt_auxii_o:NnnnnnnnN + \__fp_sqrt_auxiii_o:wnnnnnnnn + {#1#2#3#4} {#5} {2499} {9988} {7500} + } +\cs_new:Npn \__fp_sqrt_auxii_o:NnnnnnnnN #1 #2#3#4#5#6 #7#8#9 + { + \exp_after:wN #1 + \int_use:N \__int_eval:w \c__fp_big_leading_shift_int + + #7 - #2 * #2 + \exp_after:wN \__fp_pack_big:NNNNNNw + \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + - 2 * #2 * #3 + \exp_after:wN \__fp_pack_big:NNNNNNw + \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + + #8 - #3 * #3 - 2 * #2 * #4 + \exp_after:wN \__fp_pack_big:NNNNNNw + \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + - 2 * #3 * #4 - 2 * #2 * #5 + \exp_after:wN \__fp_pack_big:NNNNNNw + \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + + #9 000 0000 - #4 * #4 - 2 * #3 * #5 - 2 * #2 * #6 + \exp_after:wN \__fp_pack_big:NNNNNNw + \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + - 2 * #4 * #5 - 2 * #3 * #6 + \exp_after:wN \__fp_pack_big:NNNNNNw + \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + - #5 * #5 - 2 * #4 * #6 + \exp_after:wN \__fp_pack_big:NNNNNNw + \int_use:N \__int_eval:w + \c__fp_big_middle_shift_int + - 2 * #5 * #6 + \exp_after:wN \__fp_pack_big:NNNNNNw + \int_use:N \__int_eval:w + \c__fp_big_trailing_shift_int + - #6 * #6 ; + % ( + - 257 ) * 5000 0000 / (#2#3 + 1) + 10 0000 0000 ; + {#2}{#3}{#4}{#5}{#6} {#7}{#8}#9 + } +\cs_new:Npn \__fp_sqrt_auxiii_o:wnnnnnnnn + #1; #2#3#4#5#6#7#8#9 + { + \if_int_compare:w #1 > \c_one + \exp_after:wN \__fp_sqrt_auxiv_o:NNNNNw + \int_use:N \__int_eval:w (#1#2 %) + \else: + \if_int_compare:w #1#2 > \c_one + \exp_after:wN \__fp_sqrt_auxv_o:NNNNNw + \int_use:N \__int_eval:w (#1#2#3 %) + \else: + \if_int_compare:w #1#2#3 > \c_one + \exp_after:wN \__fp_sqrt_auxvi_o:NNNNNw + \int_use:N \__int_eval:w (#1#2#3#4 %) + \else: + \exp_after:wN \__fp_sqrt_auxvii_o:NNNNNw + \int_use:N \__int_eval:w (#1#2#3#4#5 %) + \fi: + \fi: + \fi: + } +\cs_new:Npn \__fp_sqrt_auxiv_o:NNNNNw 1#1#2#3#4#5#6; + { \__fp_sqrt_auxviii_o:nnnnnnn {#1#2#3#4#5#6} {00000000} } +\cs_new:Npn \__fp_sqrt_auxv_o:NNNNNw 1#1#2#3#4#5#6; + { \__fp_sqrt_auxviii_o:nnnnnnn {000#1#2#3#4#5} {#60000} } +\cs_new:Npn \__fp_sqrt_auxvi_o:NNNNNw 1#1#2#3#4#5#6; + { \__fp_sqrt_auxviii_o:nnnnnnn {0000000#1} {#2#3#4#5#6} } +\cs_new:Npn \__fp_sqrt_auxvii_o:NNNNNw 1#1#2#3#4#5#6; + { + \if_int_compare:w #1#2 = \c_zero + \exp_after:wN \__fp_sqrt_auxx_o:Nnnnnnnn + \fi: + \__fp_sqrt_auxviii_o:nnnnnnn {00000000} {000#1#2#3#4#5} + } +\cs_new:Npn \__fp_sqrt_auxviii_o:nnnnnnn #1#2 #3#4#5#6#7 + { + \exp_after:wN \__fp_sqrt_auxix_o:wnwnw + \int_use:N \__int_eval:w #3 + \exp_after:wN \__fp_basics_pack_low:NNNNNw + \int_use:N \__int_eval:w #1 + 1#4#5 + \exp_after:wN \__fp_basics_pack_low:NNNNNw + \int_use:N \__int_eval:w #2 + 1#6#7 ; + } +\cs_new:Npn \__fp_sqrt_auxix_o:wnwnw #1; #2#3; #4#5; + { + \__fp_sqrt_auxii_o:NnnnnnnnN + \__fp_sqrt_auxiii_o:wnnnnnnnn {#1}{#2}{#3}{#4}{#5} + } +\cs_new:Npn \__fp_sqrt_auxx_o:Nnnnnnnn #1#2#3 #4#5#6#7#8 + { + \exp_after:wN \__fp_sqrt_auxxi_o:wwnnN + \int_use:N \__int_eval:w + (#8 + 2499) / 5000 * 5000 ; + {#4} {#5} {#6} {#7} ; + } +\cs_new:Npn \__fp_sqrt_auxxi_o:wwnnN #1; #2; #3#4#5 + { + \__fp_sqrt_auxii_o:NnnnnnnnN + \__fp_sqrt_auxxii_o:nnnnnnnnw + #2 {#1} + {#3} { #4 + \c_one } #5 + } +\cs_new:Npn \__fp_sqrt_auxxii_o:nnnnnnnnw 0; #1#2#3#4#5#6#7#8 #9; + { + \if_int_compare:w #1#2 > \c_zero + \if_int_compare:w #1#2 = \c_one + \if_int_compare:w #3#4 = \c_zero + \if_int_compare:w #5#6 = \c_zero + \if_int_compare:w #7#8 = \c_zero + \__fp_sqrt_auxxiii_o:w + \fi: + \fi: + \fi: + \fi: + \exp_after:wN \__fp_sqrt_auxxiv_o:wnnnnnnnN + \__int_value:w 9998 + \else: + \exp_after:wN \__fp_sqrt_auxxiv_o:wnnnnnnnN + \__int_value:w 10000 + \fi: + ; + } +\cs_new:Npn \__fp_sqrt_auxxiii_o:w \fi: \fi: \fi: \fi: #1 \fi: ; + { + \fi: \fi: \fi: \fi: \fi: + \__fp_sqrt_auxxiv_o:wnnnnnnnN 9999 ; + } +\cs_new:Npn \__fp_sqrt_auxxiv_o:wnnnnnnnN #1; #2#3#4#5#6 #7#8#9 + { + \exp_after:wN \__fp_basics_pack_high:NNNNNw + \int_use:N \__int_eval:w 1 0000 0000 + #2#3 + \exp_after:wN \__fp_basics_pack_low:NNNNNw + \int_use:N \__int_eval:w 1 0000 0000 + + #4#5 + \if_int_compare:w #6 > #1 \exp_stop_f: + \c_one \fi: + + \exp_after:wN \__fp_round:NNN + \exp_after:wN 0 + \exp_after:wN 0 + \__int_value:w + \exp_after:wN \use_i:nn + \exp_after:wN \__fp_round_digit:Nw + \int_use:N \__int_eval:w #6 + 19999 - #1 ; + \exp_after:wN ; + } \cs_new:Npn \__fp_set_sign_o:w #1 \s__fp \__fp_chk:w #2#3#4; @ { \exp_after:wN \__fp_exp_after_o:w @@ -2875,38 +3164,37 @@ \exp_after:wN #3 \exp_after:wN { \int_use:N \__int_eval:w \c_ten_thousand + #1 } #2 ; } -\cs_new:Npn \__fp_fixed_div_myriad:wn #1#2#3#4#5#6; #7 +\cs_new:Npn \__fp_fixed_div_myriad:wn #1#2#3#4#5#6; { - \exp_after:wN \__fp_fixed_mul_after:wn + \exp_after:wN \__fp_fixed_mul_after:wwn \int_use:N \__int_eval:w \c__fp_leading_shift_int - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_trailing_shift_int - + #1 ; {#7} {#2}{#3}{#4}{#5}; + + #1 ; {#2}{#3}{#4}{#5}; } -\cs_new:Npn \__fp_fixed_mul_after:wn #1; #2 { #2 {#1} } +\cs_new:Npn \__fp_fixed_mul_after:wwn #1; #2; #3 { #3 {#1} #2; } \cs_new:Npn \__fp_fixed_mul_short:wwn #1#2#3#4#5#6; #7#8#9; { - \exp_after:wN \__fp_fixed_mul_after:wn + \exp_after:wN \__fp_fixed_mul_after:wwn \int_use:N \__int_eval:w \c__fp_leading_shift_int + #1*#7 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int + #1*#8 + #2*#7 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int + #1*#9 + #2*#8 + #3*#7 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int + #2*#9 + #3*#8 + #4*#7 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int + #3*#9 + #4*#8 + #5*#7 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_trailing_shift_int + #4*#9 + #5*#8 + #6*#7 + ( #5*#9 + #6*#8 + #6*#9 / \c_ten_thousand ) - / \c_ten_thousand - \exp_after:wN ; \__fp_use_braced_s:n + / \c_ten_thousand ; ; } \cs_new:Npn \__fp_fixed_div_int:wwN #1#2#3#4#5#6 ; #7 ; #8 { @@ -2961,79 +3249,78 @@ { #7 {#1#2#3#4#5} {#6} } \cs_new:Npn \__fp_fixed_mul:wwn #1#2#3#4 #5; #6#7#8#9 { - \exp_after:wN \__fp_fixed_mul_after:wn + \exp_after:wN \__fp_fixed_mul_after:wwn \int_use:N \__int_eval:w \c__fp_leading_shift_int - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int + #1*#6 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int + #1*#7 + #2*#6 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int + #1*#8 + #2*#7 + #3*#6 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int + #1*#9 + #2*#8 + #3*#7 + #4*#6 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_trailing_shift_int + #2*#9 + #3*#8 + #4*#7 + ( #3*#9 + #4*#8 - + \__fp_fixed_mul:nnnnnnnwn #5 {#6}{#7} {#1}{#2} + + \__fp_fixed_mul:nnnnnnnw #5 {#6}{#7} {#1}{#2} } -\cs_new:Npn \__fp_fixed_mul:nnnnnnnwn #1#2 #3#4 #5#6 #7#8 ; #9 +\cs_new:Npn \__fp_fixed_mul:nnnnnnnw #1#2 #3#4 #5#6 #7#8 ; { #1*#4 + #2*#3 + #5*#8 + #6*#7 ) / \c_ten_thousand - + #1*#3 + #5*#7 ; - {#9} ; + + #1*#3 + #5*#7 ; ; } -\cs_new:Npn \__fp_fixed_mul_add:wwwn #1; #2; #3#4#5#6#7#8; #9 +\cs_new:Npn \__fp_fixed_mul_add:wwwn #1; #2; #3#4#5#6#7#8; { - \exp_after:wN \__fp_fixed_mul_after:wn + \exp_after:wN \__fp_fixed_mul_after:wwn \int_use:N \__int_eval:w \c__fp_big_leading_shift_int - \exp_after:wN \__fp_pack_big:NNNNNNwn + \exp_after:wN \__fp_pack_big:NNNNNNw \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + #3 #4 \__fp_fixed_mul_add:Nwnnnwnnn + + #5 #6 ; #2 ; #1 ; #2 ; + - + #7 #8 ; {#9} ; + + #7 #8 ; ; } -\cs_new:Npn \__fp_fixed_mul_sub_back:wwwn #1; #2; #3#4#5#6#7#8; #9 +\cs_new:Npn \__fp_fixed_mul_sub_back:wwwn #1; #2; #3#4#5#6#7#8; { - \exp_after:wN \__fp_fixed_mul_after:wn + \exp_after:wN \__fp_fixed_mul_after:wwn \int_use:N \__int_eval:w \c__fp_big_leading_shift_int - \exp_after:wN \__fp_pack_big:NNNNNNwn + \exp_after:wN \__fp_pack_big:NNNNNNw \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + #3 #4 \__fp_fixed_mul_add:Nwnnnwnnn - + #5 #6 ; #2 ; #1 ; #2 ; - - + #7 #8 ; {#9} ; + + #7 #8 ; ; } -\cs_new:Npn \__fp_fixed_one_minus_mul:wwn #1; #2; #3 +\cs_new:Npn \__fp_fixed_one_minus_mul:wwn #1; #2; { - \exp_after:wN \__fp_fixed_mul_after:wn + \exp_after:wN \__fp_fixed_mul_after:wwn \int_use:N \__int_eval:w \c__fp_big_leading_shift_int - \exp_after:wN \__fp_pack_big:NNNNNNwn + \exp_after:wN \__fp_pack_big:NNNNNNw \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + 1 0000 0000 \__fp_fixed_mul_add:Nwnnnwnnn - ; #2 ; #1 ; #2 ; - - ; {#3} ; + ; ; } \cs_new:Npn \__fp_fixed_mul_add:Nwnnnwnnn #1 #2; #3#4#5#6; #7#8#9 { #1 #7*#3 - \exp_after:wN \__fp_pack_big:NNNNNNwn + \exp_after:wN \__fp_pack_big:NNNNNNw \int_use:N \__int_eval:w \c__fp_big_middle_shift_int #1 #7*#4 #1 #8*#3 - \exp_after:wN \__fp_pack_big:NNNNNNwn + \exp_after:wN \__fp_pack_big:NNNNNNw \int_use:N \__int_eval:w \c__fp_big_middle_shift_int #1 #7*#5 #1 #8*#4 #1 #9*#3 #2 - \exp_after:wN \__fp_pack_big:NNNNNNwn + \exp_after:wN \__fp_pack_big:NNNNNNw \int_use:N \__int_eval:w \c__fp_big_middle_shift_int #1 \__fp_fixed_mul_add:nnnnwnnnn {#7}{#8}{#9} } \cs_new:Npn \__fp_fixed_mul_add:nnnnwnnnn #1#2#3#4#5; #6#7#8#9 { ( #1*#9 + #2*#8 + #3*#7 + #4*#6 ) - \exp_after:wN \__fp_pack_big:NNNNNNwn + \exp_after:wN \__fp_pack_big:NNNNNNw \int_use:N \__int_eval:w \c__fp_big_trailing_shift_int \__fp_fixed_mul_add:nnnnwnnwN { #6 + #4*#7 + #3*#8 + #2*#9 + #1 } @@ -3876,34 +4163,34 @@ \cs_new:Npn \__fp_pow_exponent:wnN #1; #2 { \if_int_compare:w #2 > \c_zero - \exp_after:wN \__fp_pow_exponent:Nwnnnnnwn % n\ln(10) - (-\ln(x)) + \exp_after:wN \__fp_pow_exponent:Nwnnnnnw % n\ln(10) - (-\ln(x)) \exp_after:wN + \else: - \exp_after:wN \__fp_pow_exponent:Nwnnnnnwn % -( |n|\ln(10) + (-\ln(x)) ) + \exp_after:wN \__fp_pow_exponent:Nwnnnnnw % -( |n|\ln(10) + (-\ln(x)) ) \exp_after:wN - \fi: #2; #1; } -\cs_new:Npn \__fp_pow_exponent:Nwnnnnnwn #1#2; #3#4#5#6#7#8; #9 +\cs_new:Npn \__fp_pow_exponent:Nwnnnnnw #1#2; #3#4#5#6#7#8; { %^^A todo: use that in ln. - \exp_after:wN \__fp_fixed_mul_after:wn + \exp_after:wN \__fp_fixed_mul_after:wwn \int_use:N \__int_eval:w \c__fp_leading_shift_int - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int #1#2*23025 - #1 #3 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int #1 #2*8509 - #1 #4 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int #1 #2*2994 - #1 #5 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_middle_shift_int #1 #2*0456 - #1 #6 - \exp_after:wN \__fp_pack:NNNNNwn + \exp_after:wN \__fp_pack:NNNNNw \int_use:N \__int_eval:w \c__fp_trailing_shift_int #1 #2*8401 - #1 #7 - #1 ( #2*7991 - #8 ) / 1 0000 ; {#9} ; + #1 ( #2*7991 - #8 ) / 1 0000 ; ; } \cs_new:Npn \__fp_pow_B:wwN #1#2#3#4#5#6; #7; { |