summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-07-23 17:15:00 +0000
committerKarl Berry <karl@freefriends.org>2012-07-23 17:15:00 +0000
commit134349701bddf7cbbacf6030c6b9f9838aff96fa (patch)
treeec1140c46e1c0347a671a6fa3cf8af5a79e95f93 /Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
parentf7855c12c18bb97b7b9e49ab685ee558d8c0b47b (diff)
l3kernel 3990 (17jul12)
git-svn-id: svn://tug.org/texlive/trunk@27108 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3kernel/l3fp.sty')
-rw-r--r--Master/texmf-dist/tex/latex/l3kernel/l3fp.sty7063
1 files changed, 4108 insertions, 2955 deletions
diff --git a/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty b/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
index bb38caa64f6..a7680dc7803 100644
--- a/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
+++ b/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
@@ -5,6 +5,18 @@
%% The original source files were:
%%
%% l3fp.dtx (with options: `package')
+%% l3fp-aux.dtx (with options: `package')
+%% l3fp-traps.dtx (with options: `package')
+%% l3fp-round.dtx (with options: `package')
+%% l3fp-parse.dtx (with options: `package')
+%% l3fp-logic.dtx (with options: `package')
+%% l3fp-basics.dtx (with options: `package')
+%% l3fp-extended.dtx (with options: `package')
+%% l3fp-expo.dtx (with options: `package')
+%% l3fp-trig.dtx (with options: `package')
+%% l3fp-convert.dtx (with options: `package')
+%% l3fp-assign.dtx (with options: `package')
+%% l3fp-old.dtx (with options: `package')
%%
%% EXPERIMENTAL CODE
%%
@@ -13,7 +25,7 @@
%%
%% Do not distribute a modified version of this file.
%%
-%% File: l3fp.dtx Copyright (C) 2010-2012 The LaTeX3 Project
+%% File: l3fp.dtx Copyright (C) 2011-2012 The LaTeX3 Project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -42,3386 +54,4527 @@
%% Snapshots taken from the repository represent work in progress and may
%% not work or may contain conflicting material! We therefore ask
%% people _not_ to put them into distributions, archives, etc. without
-%% prior consultation with the LaTeX3 Project.
+%% prior consultation with the LaTeX3 Project Team.
%%
%% -----------------------------------------------------------------------
+%%
\RequirePackage{l3names}
-\GetIdInfo$Id: l3fp.dtx 3490 2012-03-04 01:00:53Z bruno $
- {L3 Experimental floating-point operations}
+\GetIdInfo$Id: l3fp.dtx 3986 2012-07-15 19:23:51Z joseph $
+ {L3 Floating points}
\ProvidesExplPackage
{\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
-\package_check_loaded_expl:
-\int_const:Nn \c_forty_four { 44 }
-\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
-\int_set:Nn \c_fp_pi_by_four_extended_int { 897 448 310 }
-\int_new:N \c_fp_pi_decimal_int
-\int_set:Nn \c_fp_pi_decimal_int { 141 592 653 }
-\int_new:N \c_fp_pi_extended_int
-\int_set:Nn \c_fp_pi_extended_int { 589 793 238 }
-\int_new:N \c_fp_two_pi_decimal_int
-\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_const:Nn \c_e_fp { + 2.718281828 e 0 }
-\tl_const:Nn \c_one_fp { + 1.000000000 e 0 }
-\tl_const:Nn \c_pi_fp { + 3.141592654 e 0 }
-\tl_const:Nn \c_undefined_fp { X 0.000000000 e 0 }
-\tl_const: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
-\int_new:N \l_fp_input_a_exponent_int
-\int_new:N \l_fp_input_b_sign_int
-\int_new:N \l_fp_input_b_integer_int
-\int_new:N \l_fp_input_b_decimal_int
-\int_new:N \l_fp_input_b_exponent_int
-\int_new:N \l_fp_input_a_extended_int
-\int_new:N \l_fp_input_b_extended_int
-\int_new:N \l_fp_mul_a_i_int
-\int_new:N \l_fp_mul_a_ii_int
-\int_new:N \l_fp_mul_a_iii_int
-\int_new:N \l_fp_mul_a_iv_int
-\int_new:N \l_fp_mul_a_v_int
-\int_new:N \l_fp_mul_a_vi_int
-\int_new:N \l_fp_mul_b_i_int
-\int_new:N \l_fp_mul_b_ii_int
-\int_new:N \l_fp_mul_b_iii_int
-\int_new:N \l_fp_mul_b_iv_int
-\int_new:N \l_fp_mul_b_v_int
-\int_new:N \l_fp_mul_b_vi_int
-\int_new:N \l_fp_mul_output_int
-\tl_new:N \l_fp_mul_output_tl
-\int_new:N \l_fp_output_sign_int
-\int_new:N \l_fp_output_integer_int
-\int_new:N \l_fp_output_decimal_int
-\int_new:N \l_fp_output_exponent_int
-\int_new:N \l_fp_output_extended_int
-\bool_new:N \l_fp_round_carry_bool
-\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_internal_int
-\tl_new:N \l_fp_internal_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:Npn \fp_read:N #1
- { \exp_after:wN \fp_read_aux:w #1 \q_stop }
-\cs_new_protected:Npn \fp_read_aux:w #1#2 . #3 e #4 \q_stop
- {
- \if:w #1 -
- \l_fp_input_a_sign_int \c_minus_one
- \else:
- \l_fp_input_a_sign_int \c_one
- \fi:
- \l_fp_input_a_integer_int #2 \scan_stop:
- \l_fp_input_a_decimal_int #3 \scan_stop:
- \l_fp_input_a_exponent_int #4 \scan_stop:
- }
-\cs_new_protected:Npn \fp_split:Nn #1#2
- {
- \tl_set:Nx \l_fp_internal_tl {#2}
- \tl_set_rescan:Nno \l_fp_internal_tl { \char_set_catcode_ignore:n { 32 } }
- { \l_fp_internal_tl }
- \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_internal_tl e e \q_stop #1
- }
-\cs_new_protected_nopar:Npn \fp_split_sign:
- {
- \if_int_compare:w \pdftex_strcmp:D
- { \exp_after:wN \tl_head:w \l_fp_internal_tl ? \q_stop } { - }
- = \c_zero
- \tl_set:Nx \l_fp_internal_tl
- {
- \exp_after:wN
- \tl_tail:w \l_fp_internal_tl \prg_do_nothing: \q_stop
- }
- \l_fp_split_sign_int -\l_fp_split_sign_int
- \exp_after:wN \fp_split_sign:
+\__expl_package_check:
+%% File: l3fp-aux.dtx Copyright(C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\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_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}
+\cs_new:Npn \__fp_use_ii_until_s:nnw #1#2#3; {#2}
+\cs_new:Npn \__fp_reverse_args:Nww #1 #2; #3; { #1 #3; #2; }
+\__scan_new:N \s__fp
+\cs_new_protected:Npn \__fp_chk:w #1 ;
+ {
+ \__msg_kernel_error:nnx { kernel } { misused-fp }
+ { \__fp_to_tl:w \s__fp \__fp_chk:w #1 ; }
+ }
+\__scan_new:N \s__fp_mark
+\__scan_new:N \s__fp_stop
+\__scan_new:N \s__fp_invalid
+\__scan_new:N \s__fp_underflow
+\__scan_new:N \s__fp_overflow
+\__scan_new:N \s__fp_division
+\__scan_new:N \s__fp_exact
+\tl_const:Nn \c_zero_fp { \s__fp \__fp_chk:w 0 0 \s__fp_exact ; }
+\tl_const:Nn \c_minus_zero_fp { \s__fp \__fp_chk:w 0 2 \s__fp_exact ; }
+\tl_const:Nn \c_inf_fp { \s__fp \__fp_chk:w 2 0 \s__fp_exact ; }
+\tl_const:Nn \c_minus_inf_fp { \s__fp \__fp_chk:w 2 2 \s__fp_exact ; }
+\tl_const:Nn \c_nan_fp { \s__fp \__fp_chk:w 3 1 \s__fp_exact ; }
+\int_const:Nn \c__fp_max_exponent_int { 10000 }
+\cs_new:Npn \__fp_zero_fp:N #1 { \s__fp \__fp_chk:w 0 #1 \s__fp_underflow ; }
+\cs_new:Npn \__fp_inf_fp:N #1 { \s__fp \__fp_chk:w 2 #1 \s__fp_overflow ; }
+\cs_new:Npn \__fp_min_fp:N #1
+ {
+ \s__fp \__fp_chk:w 1 #1
+ { \int_eval:n { - \c__fp_max_exponent_int } }
+ {1000} {0000} {0000} {0000} ;
+ }
+\cs_new:Npn \__fp_max_fp:N #1
+ {
+ \s__fp \__fp_chk:w 1 #1
+ { \int_use:N \c__fp_max_exponent_int }
+ {9999} {9999} {9999} {9999} ;
+ }
+\cs_new:Npn \__fp_exponent:w \s__fp \__fp_chk:w #1
+ {
+ \if_meaning:w 1 #1
+ \exp_after:wN \__fp_use_ii_until_s:nnw
\else:
- \if_int_compare:w \pdftex_strcmp:D
- { \exp_after:wN \tl_head:w \l_fp_internal_tl ? \q_stop } { + }
- = \c_zero
- \tl_set:Nx \l_fp_internal_tl
- {
- \exp_after:wN
- \tl_tail:w \l_fp_internal_tl \prg_do_nothing: \q_stop
- }
- \exp_after:wN \exp_after:wN \exp_after:wN \fp_split_sign:
- \fi:
+ \exp_after:wN \__fp_use_i_until_s:nw
+ \exp_after:wN 0
\fi:
}
-\cs_new_protected:Npn \fp_split_exponent:w #1 e #2 e #3 \q_stop #4
+\cs_new:Npn \__fp_sanitize:Nw #1 #2;
{
- \use:c { l_fp_input_ #4 _exponent_int }
- \int_eval:w 0 #2 \scan_stop:
- \tex_afterassignment:D \fp_split_aux_i:w
- \use:c { l_fp_input_ #4 _integer_int }
- \int_eval:w 0 #1 . . \q_stop #4
+ \if_case:w \if_int_compare:w #2 > \c__fp_max_exponent_int \c_one \else:
+ \if_int_compare:w #2 < - \c__fp_max_exponent_int \c_two \else:
+ \if_meaning:w 1 #1 \c_three \else: \c_zero \fi: \fi: \fi:
+ \or: \exp_after:wN \__fp_overflow:w
+ \or: \exp_after:wN \__fp_underflow:w
+ \or: \exp_after:wN \__fp_sanitize_zero:w
+ \fi:
+ \s__fp \__fp_chk:w 1 #1 {#2}
}
-\cs_new_protected:Npn \fp_split_aux_i:w #1 . #2 . #3 \q_stop
- { \fp_split_aux_ii:w #2 000000000 \q_stop }
-\cs_new_protected:Npn \fp_split_aux_ii:w #1#2#3#4#5#6#7#8#9
- { \fp_split_aux_iii:w {#1#2#3#4#5#6#7#8#9} }
-\cs_new_protected:Npn \fp_split_aux_iii:w #1#2 \q_stop
+\cs_new:Npn \__fp_sanitize:wN #1; #2 { \__fp_sanitize:Nw #2 #1; }
+\cs_new:Npn \__fp_sanitize_zero:w \s__fp \__fp_chk:w #1 #2 #3; { \c_zero_fp }
+\cs_new:Npn \__fp_exp_after_o:w \s__fp \__fp_chk:w #1
{
- \l_fp_internal_int 1 #1 \scan_stop:
- \exp_after:wN \fp_split_decimal:w
- \int_use:N \l_fp_internal_int 000000000 \q_stop
+ \if_meaning:w 1 #1
+ \exp_after:wN \__fp_exp_after_normal:nNNw
+ \else:
+ \exp_after:wN \__fp_exp_after_special:nNNw
+ \fi:
+ { }
+ #1
}
-\cs_new_protected:Npn \fp_split_decimal:w #1#2#3#4#5#6#7#8#9
- { \fp_split_decimal_aux:w {#2#3#4#5#6#7#8#9} }
-\cs_new_protected:Npn \fp_split_decimal_aux:w #1#2#3 \q_stop #4
+\cs_new:Npn \__fp_exp_after_o:nw #1 \s__fp \__fp_chk:w #2
{
- \use:c { l_fp_input_ #4 _decimal_int } #1#2 \scan_stop:
- \if_int_compare:w
- \int_eval:w
- \use:c { l_fp_input_ #4 _integer_int } +
- \use:c { l_fp_input_ #4 _decimal_int }
- \scan_stop:
- = \c_zero
- \use:c { l_fp_input_ #4 _sign_int } \c_one
+ \if_meaning:w 1 #2
+ \exp_after:wN \__fp_exp_after_normal:nNNw
+ \else:
+ \exp_after:wN \__fp_exp_after_special:nNNw
\fi:
- \if_int_compare:w
- \use:c { l_fp_input_ #4 _integer_int } < \c_one_thousand_million
+ { #1 }
+ #2
+ }
+\cs_new:Npn \__fp_exp_after_f:nw #1 \s__fp \__fp_chk:w #2
+ {
+ \if_meaning:w 1 #2
+ \exp_after:wN \__fp_exp_after_normal:nNNw
\else:
- \exp_after:wN \fp_overflow_msg:
+ \exp_after:wN \__fp_exp_after_special:nNNw
\fi:
+ { \tex_romannumeral:D -`0 #1 }
+ #2
}
-\cs_new_protected:Npn \fp_standardise:NNNN #1#2#3#4
+\cs_new:Npn \__fp_exp_after_special:nNNw #1#2#3#4;
{
- \if_int_compare:w
- \int_eval:w #2 + #3 = \c_zero
- #1 \c_one
- #4 \c_zero
- \exp_after:wN \use_none:nnnn
+ \exp_after:wN \s__fp
+ \exp_after:wN \__fp_chk:w
+ \exp_after:wN #2
+ \exp_after:wN #3
+ \exp_after:wN #4
+ \exp_after:wN ;
+ #1
+ }
+\cs_new:Npn \__fp_exp_after_normal:nNNw #1 1 #2 #3 #4#5#6#7;
+ {
+ \exp_after:wN \__fp_exp_after_normal:Nwwwww
+ \exp_after:wN #2
+ \__int_value:w #3 \exp_after:wN ;
+ \__int_value:w 1 #4 \exp_after:wN ;
+ \__int_value:w 1 #5 \exp_after:wN ;
+ \__int_value:w 1 #6 \exp_after:wN ;
+ \__int_value:w 1 #7 \exp_after:wN ; #1
+ }
+\cs_new:Npn \__fp_exp_after_normal:Nwwwww
+ #1 #2; 1 #3 ; 1 #4 ; 1 #5 ; 1 #6 ;
+ { \s__fp \__fp_chk:w 1 #1 {#2} {#3} {#4} {#5} {#6} ; }
+\int_const:Nn \c__fp_leading_shift_int { - 5 0000 }
+\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} }
+\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_twice_four:wNNNNNNNN #1; #2#3#4#5 #6#7#8#9
+ { #1 {#2#3#4#5} {#6#7#8#9} ; }
+\cs_new:Npn \__fp_decimate:nNnnnn #1
+ {
+ \cs:w
+ __fp_decimate_
+ \if_int_compare:w \__int_eval:w #1 > \c_sixteen
+ tiny
+ \else:
+ \tex_romannumeral:D \__int_eval:w #1
+ \fi:
+ :Nnnnn
+ \cs_end:
+ }
+\cs_new:Npn \__fp_decimate_:Nnnnn #1 #2#3#4#5
+ { #1 0 {#2#3} {#4#5} ; }
+\cs_new:Npn \__fp_decimate_tiny:Nnnnn #1 #2#3#4#5
+ { #1 1 { 0000 0000 } { 0000 0000 } 0 #2#3#4#5 ; }
+\cs_new:Npn \__fp_tmp:w #1 #2 #3
+ {
+ \cs_new:cpn { __fp_decimate_ #1 :Nnnnn } ##1 ##2##3##4##5
+ {
+ \exp_after:wN ##1
+ \__int_value:w
+ \exp_after:wN \__fp_decimate_round:Nw #2 ;
+ \__fp_decimate_pack:nnnnnnnnnnw #3 ;
+ }
+ }
+\__fp_tmp:w {i} {\use_none:nnn #50} { 0{#2}#3{#4}#5 }
+\__fp_tmp:w {ii} {\use_none:nn #5 } { 00{#2}#3{#4}#5 }
+\__fp_tmp:w {iii} {\use_none:n #5 } { 000{#2}#3{#4}#5 }
+\__fp_tmp:w {iv} { #5 } { {0000}#2{#3}#4 #5 }
+\__fp_tmp:w {v} {\use_none:nnn #4#5 } { 0{0000}#2{#3}#4 #5 }
+\__fp_tmp:w {vi} {\use_none:nn #4#5 } { 00{0000}#2{#3}#4 #5 }
+\__fp_tmp:w {vii} {\use_none:n #4#5 } { 000{0000}#2{#3}#4 #5 }
+\__fp_tmp:w {viii}{ #4#5 } { {0000}0000{#2}#3 #4 #5 }
+\__fp_tmp:w {ix} {\use_none:nnn #3#4+#5} { 0{0000}0000{#2}#3 #4 #5 }
+\__fp_tmp:w {x} {\use_none:nn #3#4+#5} { 00{0000}0000{#2}#3 #4 #5 }
+\__fp_tmp:w {xi} {\use_none:n #3#4+#5} { 000{0000}0000{#2}#3 #4 #5 }
+\__fp_tmp:w {xii} { #3#4+#5} { {0000}0000{0000}#2 #3 #4 #5 }
+\__fp_tmp:w {xiii}{\use_none:nnn#2#3+#4#5} { 0{0000}0000{0000}#2 #3 #4 #5 }
+\__fp_tmp:w {xiv} {\use_none:nn #2#3+#4#5} { 00{0000}0000{0000}#2 #3 #4 #5 }
+\__fp_tmp:w {xv} {\use_none:n #2#3+#4#5} { 000{0000}0000{0000}#2 #3 #4 #5 }
+\__fp_tmp:w {xvi} { #2#3+#4#5} {{0000}0000{0000}0000 #2 #3 #4 #5 }
+\cs_new:Npn \__fp_decimate_round:Nw #1 #2;
+ {
+ \if_int_odd:w \if_meaning:w 0 #1 \c_one \else:
+ \if_meaning:w 5 #1 \c_one \else:
+ \c_zero \fi: \fi:
+ \if_int_compare:w \__int_eval:w #2 > \c_zero
+ \__int_eval:w 1 +
+ \fi:
+ \fi:
+ #1
+ }
+\cs_new:Npn \__fp_decimate_pack:nnnnnnnnnnw #1#2#3#4#5
+ { \__fp_decimate_pack_ii:nnnnnnw { #1#2#3#4#5 } }
+\cs_new:Npn \__fp_decimate_pack_ii:nnnnnnw #1 #2#3#4#5#6
+ { {#1} {#2#3#4#5#6} }
+\cs_new:Npn \__fp_case_use:nw #1#2 \fi: #3 \s__fp { \fi: #1 \s__fp }
+\cs_new:Npn \__fp_case_return:nw #1#2 \fi: #3 ; { \fi: #1 }
+\cs_new:Npn \__fp_case_return_o:Nw #1#2 \fi: #3 \s__fp #4 ;
+ { \fi: \exp_after:wN #1 }
+\cs_new:Npn \__fp_case_return_same_o:w #1 \fi: #2 \s__fp
+ { \fi: \__fp_exp_after_o:w \s__fp }
+\cs_new:Npn \__fp_case_return_o:Nww #1#2 \fi: #3 \s__fp #4 ; #5 ;
+ { \fi: \exp_after:wN #1 }
+\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
+ {
+ \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
+ \else: \__fp_case_return:nw \use_ii:nn
+ \fi:
+ }
+\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:
+ \else:
+ \exp_after:wN \use_iii:nnn
+ \fi:
+ ;
+ }
+\cs_new:Npn \__fp_small_int_test:NnnwNTF #1#2#3#4; #5
+ {
+ \if_meaning:w 0 #1
+ \exp_after:wN \__fp_small_int_true:wTF
+ \__int_value:w \if_meaning:w 2 #5 - \fi: #3
\else:
- \exp_after:wN \fp_standardise_aux:NNNN
+ \exp_after:wN \use_iii:nnn
\fi:
- #1#2#3#4
}
-\cs_new_protected:Npn \fp_standardise_aux:NNNN #1#2#3#4
+\cs_new:Npn \__fp_array_count:w #1 @
{
- \cs_set_protected_nopar:Npn \fp_standardise_aux:
+ \int_use:N \__int_eval:w \c_zero
+ \__fp_array_count_loop:Nw #1 { ? \__prg_break: } ;
+ \__prg_break_point:
+ \__int_eval_end:
+ }
+\cs_new:Npn \__fp_array_count_loop:Nw #1#2;
+ { \use_none:n #1 + \c_one \__fp_array_count_loop:Nw }
+\__msg_kernel_new:nnnn { kernel } { misused-fp }
+ { A~floating~point~with~value~'#1'~was~misused. }
+ {
+ To~obtain~the~value~of~a~floating~point~variable,~use~
+ '\token_to_str:N \fp_to_decimal:N',~
+ '\token_to_str:N \fp_to_scientific:N',~or~other~
+ conversion~functions.
+ }
+%%
+%% File: l3fp-traps.dtx Copyright (C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\cs_new_protected:Npn \__fp_flag_off:n #1
+ { \cs_set_eq:cN { l__fp_ #1 _flag_token } \c_undefined:D }
+\cs_new:Npn \__fp_flag_on:n #1
+ { \exp_args:Nc \use_none:n { l__fp_ #1 _flag_token } }
+\prg_new_conditional:Npnn \__fp_if_flag_on:n #1 { p , T , F , TF }
+ {
+ \if_cs_exist:w l__fp_ #1 _flag_token \cs_end:
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ }
+\cs_new_eq:NN \l__fp_invalid_operation_flag_token \c_undefined:D
+\cs_new_eq:NN \l__fp_division_by_zero_flag_token \c_undefined:D
+\cs_new_eq:NN \l__fp_overflow_flag_token \c_undefined:D
+\cs_new_eq:NN \l__fp_underflow_flag_token \c_undefined:D
+\cs_new_protected:Npn \__fp_trap:nn #1#2
+ {
+ \cs_if_exist_use:cF { __fp_trap_#1_set_#2: }
{
- \if_int_compare:w #2 = \c_zero
- \tex_advance:D #3 \c_one_thousand_million
- \exp_after:wN \fp_standardise_aux:w
- \int_use:N #3 \q_stop
- \exp_after:wN \fp_standardise_aux:
- \fi:
+ \clist_if_in:nnTF
+ { invalid_operation , division_by_zero , overflow , underflow }
+ {#1}
+ {
+ \__msg_kernel_error:nnxx { kernel }
+ { unknown-fpu-trap-type } {#1} {#2}
+ }
+ { \__msg_kernel_error:nnx { kernel } { unknown-fpu-exception } {#1} }
}
- \cs_set_protected:Npn
- \fp_standardise_aux:w ##1##2##3##4##5##6##7##8##9 \q_stop
+ }
+\cs_new_protected_nopar:Npn \__fp_trap_invalid_operation_set_error:
+ { \__fp_trap_invalid_operation_set:N \prg_do_nothing: }
+\cs_new_protected_nopar:Npn \__fp_trap_invalid_operation_set_flag:
+ { \__fp_trap_invalid_operation_set:N \use_none:nn }
+\cs_new_protected_nopar:Npn \__fp_trap_invalid_operation_set_none:
+ { \__fp_trap_invalid_operation_set:N \use_none:nnnn }
+\cs_new_protected:Npn \__fp_trap_invalid_operation_set:N #1
+ {
+ \__fp_trap_invalid_operation_set:Nnn #1
+ { invalid_operation } { Invalid~operation~ }
+ }
+\cs_new_protected_nopar:Npn \__fp_trap_division_by_zero_set_error:
+ { \__fp_trap_division_by_zero_set:N \prg_do_nothing: }
+\cs_new_protected_nopar:Npn \__fp_trap_division_by_zero_set_flag:
+ { \__fp_trap_division_by_zero_set:N \use_none:nn }
+\cs_new_protected_nopar:Npn \__fp_trap_division_by_zero_set_none:
+ { \__fp_trap_division_by_zero_set:N \use_none:nnnn }
+\cs_new_protected:Npn \__fp_trap_division_by_zero_set:N #1
+ {
+ \__fp_trap_invalid_operation_set:Nnn #1
+ { division_by_zero } { Division~by~zero~in~ }
+ }
+\cs_new_protected:Npn \__fp_trap_invalid_operation_set:Nnn #1#2#3
+ {
+ \exp_args:Nno \use:n
+ { \cs_set:cpn { __fp_ #2 :Nnw } ##1##2##3; }
{
- #2 ##2 \scan_stop:
- #3 ##3##4##5##6##7##8##9 0 \scan_stop:
- \tex_advance:D #4 \c_minus_one
+ #1
+ \__fp_error:x { { #3 ##2 } ( \__fp_to_tl:w ##3; ) }
+ \__fp_flag_on:n {#2}
+ \exp_after:wN ##1
}
- \fp_standardise_aux:
- \cs_set_protected_nopar:Npn \fp_standardise_aux:
+ \exp_args:Nno \use:n
+ { \cs_set:cpn { __fp_ #2 :Nnww } ##1##2##3; ##4; }
{
- \if_int_compare:w #2 > \c_nine
- \tex_advance:D #2 \c_one_thousand_million
- \exp_after:wN \use_i:nn \exp_after:wN
- \fp_standardise_aux:w \int_use:N #2
- \exp_after:wN \fp_standardise_aux:
- \fi:
+ #1
+ \__fp_error:x
+ {
+ {#3}
+ \tl_if_single:nTF {##2}
+ { ( \__fp_to_tl:w ##3; ) ##2 ( \__fp_to_tl:w ##4; ) }
+ { { ##2 ( } \__fp_to_tl:w ##3; { , ~ } \__fp_to_tl:w ##4; ) }
+ }
+ \__fp_flag_on:n {#2}
+ \exp_after:wN ##1
}
- \cs_set_protected:Npn
- \fp_standardise_aux:w ##1##2##3##4##5##6##7##8##9
+ }
+\cs_new_protected_nopar:Npn \__fp_trap_overflow_set_error:
+ { \__fp_trap_overflow_set:N \prg_do_nothing: }
+\cs_new_protected_nopar:Npn \__fp_trap_overflow_set_flag:
+ { \__fp_trap_overflow_set:N \use_none:nn }
+\cs_new_protected_nopar:Npn \__fp_trap_overflow_set_none:
+ { \__fp_trap_overflow_set:N \use_none:nnnn }
+\cs_new_protected:Npn \__fp_trap_overflow_set:N #1
+ { \__fp_trap_overflow_set:NnNn #1 { overflow } \__fp_inf_fp:N { inf } }
+\cs_new_protected_nopar:Npn \__fp_trap_underflow_set_error:
+ { \__fp_trap_underflow_set:N \prg_do_nothing: }
+\cs_new_protected_nopar:Npn \__fp_trap_underflow_set_flag:
+ { \__fp_trap_underflow_set:N \use_none:nn }
+\cs_new_protected_nopar:Npn \__fp_trap_underflow_set_none:
+ { \__fp_trap_underflow_set:N \use_none:nnnn }
+\cs_new_protected:Npn \__fp_trap_underflow_set:N #1
+ { \__fp_trap_overflow_set:NnNn #1 { underflow } \__fp_zero_fp:N { 0 } }
+\cs_new_protected:Npn \__fp_trap_overflow_set:NnNn #1#2#3#4
+ {
+ \exp_args:Nno \use:n
+ { \cs_set:cpn { __fp_ #2 :w } \s__fp \__fp_chk:w ##1##2##3; }
{
- #2 ##1##2##3##4##5##6##7##8 \scan_stop:
- \tex_advance:D #3 \c_one_thousand_million
- \tex_divide:D #3 \c_ten
- \tl_set:Nx \l_fp_internal_tl
+ #1
+ \__fp_error:x
{
- ##9
- \exp_after:wN \use_none:n \int_use:N #3
+ \token_if_eq_meaning:NNTF 1 ##1
+ {
+ \__fp_to_tl:w \s__fp \__fp_chk:w ##1##2##3; ~ #2 ed ~ to ~
+ \token_if_eq_meaning:NNF 0 ##2 { - } #4 .
+ }
+ { An~#2~occurred. }
}
- #3 \l_fp_internal_tl \scan_stop:
- \tex_advance:D #4 \c_one
+ \__fp_flag_on:n {#2}
+ #3 ##2
}
- \fp_standardise_aux:
- \if_int_compare:w #4 < \c_one_hundred
- \if_int_compare:w #4 > -\c_one_hundred
- \else:
- #1 \c_one
- #2 \c_zero
- #3 \c_zero
- #4 \c_zero
+ }
+\cs_new_protected_nopar:Npn \__fp_invalid_operation:Nnw { }
+\cs_new_protected_nopar:Npn \__fp_invalid_operation:Nnww { }
+\cs_new_protected_nopar:Npn \__fp_division_by_zero:Nnw { }
+\cs_new_protected_nopar:Npn \__fp_division_by_zero:Nnww { }
+\cs_new_protected_nopar:Npn \__fp_overflow:w { }
+\cs_new_protected_nopar:Npn \__fp_underflow:w { }
+\__fp_trap:nn { invalid_operation } { error }
+\__fp_trap:nn { division_by_zero } { flag }
+\__fp_trap:nn { overflow } { flag }
+\__fp_trap:nn { underflow } { flag }
+\cs_new_eq:NN \__fp_error:n \__msg_expandable_error:n
+\cs_new:Npn \__fp_error:x #1
+ {
+ \exp_args:Nf \__msg_expandable_error:n
+ {
+ \__fp_error_loop:nwnN { \exp_stop_f: } #1 \prg_do_nothing:
+ \s__fp_mark { } \__fp_error_loop:nwnN \s__fp_mark { } \__fp_error_end:nw
+ }
+ }
+\cs_new:Npn \__fp_error_end:nw #1#2 \__fp_error_end:nw { #1 }
+\cs_new:Npn \__fp_error_loop:nwnN #1#2 \s__fp_mark #3 #4
+ {
+ \exp_after:wN #4 \tex_romannumeral:D -`0
+ #2
+ \s__fp_mark { #3 #1 } #4
+ }
+\msg_new:nnnn { kernel } { unknown-fpu-exception }
+ { The~FPU~exception~'#1'~is~not~known:~that~trap~will~never~be~triggered. }
+ {
+ The~only~exceptions~to~which~traps~can~be~attached~are \\
+ \iow_indent:n
+ {
+ * ~ invalid_operation \\
+ * ~ division_by_zero \\
+ * ~ overflow \\
+ * ~ underflow
+ }
+ }
+\msg_new:nnnn { kernel } { unknown-fpu-trap-type }
+ { The~FPU~trap~type~'#2'~is~not~known. }
+ {
+ The~trap~type~must~be~one~of \\
+ \iow_indent:n
+ {
+ * ~ error \\
+ * ~ flag \\
+ * ~ none
+ }
+ }
+%% File: l3fp-round.dtx Copyright(C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\cs_new:Npn \__fp_round_return_one:
+ { \exp_after:wN \c_one \tex_romannumeral:D }
+\cs_new:Npn \__fp_round_to_ninf:NNN #1 #2 #3
+ {
+ \if_meaning:w 2 #1
+ \if_int_compare:w #3 > \c_zero
+ \__fp_round_return_one:
\fi:
- \else:
- \exp_after:wN \fp_overflow_msg:
\fi:
+ \c_zero
}
-\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:
+\cs_new:Npn \__fp_round_to_zero:NNN #1 #2 #3 { \c_zero }
+\cs_new:Npn \__fp_round_to_pinf:NNN #1 #2 #3
{
- \if_int_compare:w \l_fp_input_a_exponent_int > \l_fp_input_b_exponent_int
- \exp_after:wN \fp_level_input_exponents_a:
+ \if_meaning:w 0 #1
+ \if_int_compare:w #3 > \c_zero
+ \__fp_round_return_one:
+ \fi:
+ \fi:
+ \c_zero
+ }
+\cs_new:Npn \__fp_round_to_nearest:NNN #1 #2 #3
+ {
+ \if_int_compare:w #3 > \c_five
+ \__fp_round_return_one:
\else:
- \exp_after:wN \fp_level_input_exponents_b:
+ \if_meaning:w 5 #3
+ \if_int_odd:w #2 \exp_stop_f:
+ \__fp_round_return_one:
+ \fi:
+ \fi:
\fi:
+ \c_zero
+ }
+\cs_new_eq:NN \__fp_round:NNN \__fp_round_to_nearest:NNN
+\cs_new:Npn \__fp_round_s:NNNw #1 #2 #3 #4;
+ {
+ \exp_after:wN \__fp_round:NNN
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \int_use:N \__int_eval:w
+ \if_int_odd:w 0 \if_meaning:w 0 #3 1 \fi:
+ \if_meaning:w 5 #3 1 \fi:
+ \exp_stop_f:
+ \if_int_compare:w \__int_eval:w #4 > \c_zero
+ 1 +
+ \fi:
+ \fi:
+ #3
+ ;
+ }
+\cs_new:Npn \__fp_round:NNNN #1 #2 #3 #4
+ {
+ \exp_after:wN \__fp_round:NNN
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \int_use:N \__int_eval:w
+ \if_int_odd:w 0 \if_meaning:w 0 #3 1 \fi:
+ \if_meaning:w 5 #3 1 \fi:
+ \exp_stop_f:
+ \if_int_compare:w #4 > \c_zero
+ 1 +
+ \fi:
+ \fi:
+ #3
+ \__int_eval_end:
}
-\cs_new_protected_nopar:Npn \fp_level_input_exponents_a:
+\cs_new:Npn \__fp_round_to_ninf_neg:NNN #1 #2 #3
{
- \if_int_compare:w \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
- \fp_level_input_exponents_a:NNNNNNNNN
- \int_use:N \l_fp_input_b_integer_int
- \exp_after:wN \fp_level_input_exponents_a:
+ \if_meaning:w 0 #1
+ \if_int_compare:w #3 > \c_zero
+ \__fp_round_return_one:
+ \fi:
\fi:
+ \c_zero
}
-\cs_new_protected:Npn \fp_level_input_exponents_a:NNNNNNNNN
- #1#2#3#4#5#6#7#8#9
+\cs_new:Npn \__fp_round_to_zero_neg:NNN #1 #2 #3
{
- \l_fp_input_b_integer_int #1#2#3#4#5#6#7#8 \scan_stop:
- \tex_advance:D \l_fp_input_b_decimal_int \c_one_thousand_million
- \tex_divide:D \l_fp_input_b_decimal_int \c_ten
- \tl_set:Nx \l_fp_internal_tl
- {
- #9
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_input_b_decimal_int
- }
- \l_fp_input_b_decimal_int \l_fp_internal_tl \scan_stop:
- \tex_advance:D \l_fp_input_b_exponent_int \c_one
+ \if_int_compare:w #3 > \c_zero
+ \__fp_round_return_one:
+ \fi:
+ \c_zero
}
-\cs_new_protected_nopar:Npn \fp_level_input_exponents_b:
+\cs_new:Npn \__fp_round_to_pinf_neg:NNN #1 #2 #3
{
- \if_int_compare:w \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
- \fp_level_input_exponents_b:NNNNNNNNN
- \int_use:N \l_fp_input_a_integer_int
- \exp_after:wN \fp_level_input_exponents_b:
+ \if_meaning:w 2 #1
+ \if_int_compare:w #3 > \c_zero
+ \__fp_round_return_one:
+ \fi:
\fi:
+ \c_zero
}
-\cs_new_protected:Npn \fp_level_input_exponents_b:NNNNNNNNN
- #1#2#3#4#5#6#7#8#9
+\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:Nww #1#2 ; #3 ;
{
- \l_fp_input_a_integer_int #1#2#3#4#5#6#7#8 \scan_stop:
- \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
- \tex_divide:D \l_fp_input_a_decimal_int \c_ten
- \tl_set:Nx \l_fp_internal_tl
+ \__fp_small_int:wTF #3; { \__fp_round:Nwn #1#2; }
{
- #9
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_input_a_decimal_int
+ \__fp_error:x { {round(x,n)~with~n=} \__fp_to_tl:w #3; }
+ \exp_after:wN \c_nan_fp
}
- \l_fp_input_a_decimal_int \l_fp_internal_tl \scan_stop:
- \tex_advance:D \l_fp_input_a_exponent_int \c_one
}
-\cs_new_protected:Npn \fp_tmp:w #1#2 { }
-\cs_new_protected:Npn \fp_new:N #1
+\cs_new:Npn \__fp_round:Nwn #1 \s__fp \__fp_chk:w #2#3#4; #5
{
- \tl_new:N #1
- \tl_gset_eq:NN #1 \c_zero_fp
+ \if_meaning:w 1 #2
+ \exp_after:wN \__fp_round_normal:NwNNnw
+ \exp_after:wN #1
+ \__int_value:w #5
+ \else:
+ \exp_after:wN \__fp_exp_after_o:w
+ \fi:
+ \s__fp \__fp_chk:w #2#3#4;
}
-\cs_generate_variant:Nn \fp_new:N { c }
-\cs_new_protected:Npn \fp_const:Nn #1#2
+\cs_new:Npn \__fp_round_normal:NwNNnw #1#2 \s__fp \__fp_chk:w 1#3#4#5;
{
- \fp_new:N #1
- \fp_gset:Nn #1 {#2}
+ \__fp_decimate:nNnnnn { \c_sixteen - #4 - #2 }
+ \__fp_round_normal_ii:NnnwNNnn #5 #1 #3 {#4} {#2}
}
-\cs_generate_variant:Nn \fp_const:Nn { c }
-\cs_new_protected:Npn \fp_zero:N #1
- { \tl_set_eq:NN #1 \c_zero_fp }
-\cs_new_protected:Npn \fp_gzero:N #1
- { \tl_gset_eq:NN #1 \c_zero_fp }
-\cs_generate_variant:Nn \fp_zero:N { c }
-\cs_generate_variant:Nn \fp_gzero:N { c }
-\cs_new_protected:Npn \fp_zero_new:N #1
- { \fp_if_exist:NTF #1 { \fp_zero:N #1 } { \fp_new:N #1 } }
-\cs_new_protected:Npn \fp_gzero_new:N #1
- { \fp_if_exist:NTF #1 { \fp_gzero:N #1 } { \fp_new:N #1 } }
-\cs_generate_variant:Nn \fp_zero_new:N { c }
-\cs_generate_variant:Nn \fp_gzero_new:N { c }
-\cs_new_protected_nopar:Npn \fp_set:Nn { \fp_set_aux:NNn \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gset:Nn { \fp_set_aux:NNn \tl_gset:Nn }
-\cs_new_protected:Npn \fp_set_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_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2
- {
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- -
- \else:
- +
- \fi:
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_input_a_decimal_int
- e
- \int_use:N \l_fp_input_a_exponent_int
- }
- }
- \fp_tmp:w
- }
-\cs_generate_variant:Nn \fp_set:Nn { c }
-\cs_generate_variant:Nn \fp_gset:Nn { c }
-\cs_new_protected_nopar:Npn \fp_set_from_dim:Nn
- { \fp_set_from_dim_aux:NNn \tl_set:Nx }
-\cs_new_protected_nopar:Npn \fp_gset_from_dim:Nn
- { \fp_set_from_dim_aux:NNn \tl_gset:Nx }
-\cs_new_protected:Npn \fp_set_from_dim_aux:NNn #1#2#3
- {
- \group_begin:
- \l_fp_internal_skip \etex_glueexpr:D #3 \scan_stop:
- \l_fp_internal_dim \l_fp_internal_skip
- \fp_split:Nn a
- {
- \exp_after:wN \fp_set_from_dim_aux:w
- \dim_use:N \l_fp_internal_dim
- }
- \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_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2
- {
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- -
- \else:
- +
- \fi:
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_input_a_decimal_int
- e
- \int_use:N \l_fp_input_a_exponent_int
- }
- }
- \fp_tmp:w
+\cs_new:Npn \__fp_round_normal_ii:NnnwNNnn #1#2#3#4; #5#6
+ {
+ \exp_after:wN \__fp_round_normal_iii:NNwNnn
+ \int_use:N \__int_eval:w
+ \if_int_compare:w #2 > \c_zero
+ 1 \__int_value:w #2
+ \exp_after:wN \__fp_round_pack:Nw
+ \int_use:N \__int_eval:w 1#3 +
+ \else:
+ \if_int_compare:w #3 > \c_zero
+ 1 \__int_value:w #3 +
+ \fi:
+ \fi:
+ \exp_after:wN #5
+ \exp_after:wN #6
+ \use_none:nnnnnnn #3
+ #1
+ \__int_eval_end:
+ 0000 0000 0000 0000 ; #6
}
-\cs_set_protected_nopar:Npx \fp_set_from_dim_aux:w
+\cs_new:Npn \__fp_round_pack:Nw #1
+ { \if_meaning:w 2 #1 + \c_one \fi: \__int_eval_end: }
+\cs_new:Npn \__fp_round_normal_iii:NNwNnn #1 #2
{
- \cs_set:Npn \exp_not:N \fp_set_from_dim_aux:w
- ##1 \tl_to_str:n { pt } {##1}
+ \if_meaning:w 0 #2
+ \exp_after:wN \__fp_round_special:NwwNnn
+ \exp_after:wN #1
+ \fi:
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_round_normal_end:wwNnn
+ ; #2
}
-\fp_set_from_dim_aux:w
-\cs_generate_variant:Nn \fp_set_from_dim:Nn { c }
-\cs_generate_variant:Nn \fp_gset_from_dim:Nn { c }
-\dim_new:N \l_fp_internal_dim
-\skip_new:N \l_fp_internal_skip
-\cs_new_eq:NN \fp_set_eq:NN \tl_set_eq:NN
-\cs_new_eq:NN \fp_set_eq:cN \tl_set_eq:cN
-\cs_new_eq:NN \fp_set_eq:Nc \tl_set_eq:Nc
-\cs_new_eq:NN \fp_set_eq:cc \tl_set_eq:cc
-\cs_new_eq:NN \fp_gset_eq:NN \tl_gset_eq:NN
-\cs_new_eq:NN \fp_gset_eq:cN \tl_gset_eq:cN
-\cs_new_eq:NN \fp_gset_eq:Nc \tl_gset_eq:Nc
-\cs_new_eq:NN \fp_gset_eq:cc \tl_gset_eq:cc
-\cs_new_eq:NN \fp_show:N \tl_show:N
-\cs_new_eq:NN \fp_show:c \tl_show:c
-\cs_new:Npn \fp_use:N #1
- { \exp_after:wN \fp_use_aux:w #1 \q_stop }
-\cs_generate_variant:Nn \fp_use:N { c }
-\cs_new:Npn \fp_use_aux:w #1#2 e #3 \q_stop
+\cs_new:Npn \__fp_round_normal_end:wwNnn #1;#2;#3#4#5
{
- \if:w #1 -
- -
+ \exp_after:wN \__fp_exp_after_o:w \tex_romannumeral:D -`0
+ \__fp_sanitize:Nw #3 #4 ; #1 ;
+ }
+\cs_new:Npn \__fp_round_special:NwwNnn #1#2;#3;#4#5#6
+ {
+ \if_meaning:w 0 #1
+ \__fp_case_return:nw
+ { \exp_after:wN \__fp_zero_fp:N \exp_after:wN #4 }
+ \else:
+ \exp_after:wN \__fp_round_special_aux:Nw
+ \exp_after:wN #4
+ \int_use:N \__int_eval:w \c_one
+ \if_meaning:w 1 #1 -#6 \else: +#5 \fi:
\fi:
- \if_int_compare:w #3 > \c_zero
- \exp_after:wN \fp_use_large:w
+ ;
+ }
+\cs_new:Npn \__fp_round_special_aux:Nw #1#2;
+ {
+ \exp_after:wN \__fp_exp_after_o:w \tex_romannumeral:D -`0
+ \__fp_sanitize:Nw #1#2; {1000}{0000}{0000}{0000};
+ }
+%% File: l3fp-parse.dtx Copyright (C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\cs_new:Npn \__fp_parse_expand:w #1 { -`0 #1 }
+\cs_new:Npn \__fp_parse_return_semicolon:w
+ #1 \fi: \__fp_parse_expand:w { \fi: ; #1 }
+\group_begin:
+\char_set_catcode_other:N \S
+\char_set_catcode_other:N \F
+\char_set_catcode_other:N \P
+\char_set_lccode:nn { `\- } { `\_ }
+\tl_to_lowercase:n
+ {
+ \group_end:
+ \cs_new:Npn \__fp_type_from_scan:N #1
+ {
+ \exp_after:wN \__fp_type_from_scan:w
+ \token_to_str:N #1 \q_mark S--FP \q_mark \q_stop
+ }
+ \cs_new:Npn \__fp_type_from_scan:w #1 S--FP #2 \q_mark #3 \q_stop {#2}
+ }
+\cs_set_protected:Npn \__fp_tmp:w #1 #2 #3
+ {
+ \cs_new:cpn { __fp_parse_digits_ #1 :N } ##1
+ {
+ \if_int_compare:w \c_nine < 1 \token_to_str:N ##1 \exp_stop_f:
+ \token_to_str:N ##1 \exp_after:wN #2 \tex_romannumeral:D
+ \else:
+ \__fp_parse_return_semicolon:w #3 ##1
+ \fi:
+ \__fp_parse_expand:w
+ }
+ }
+\__fp_tmp:w {vii} \__fp_parse_digits_vi:N { 0000000 ; 7 }
+\__fp_tmp:w {vi} \__fp_parse_digits_v:N { 000000 ; 6 }
+\__fp_tmp:w {v} \__fp_parse_digits_iv:N { 00000 ; 5 }
+\__fp_tmp:w {iv} \__fp_parse_digits_iii:N { 0000 ; 4 }
+\__fp_tmp:w {iii} \__fp_parse_digits_ii:N { 000 ; 3 }
+\__fp_tmp:w {ii} \__fp_parse_digits_i:N { 00 ; 2 }
+\__fp_tmp:w {i} \__fp_parse_digits_:N { 0 ; 1 }
+\cs_new_nopar:Npn \__fp_parse_digits_:N { ; ; 0 }
+\cs_new:Npn \__fp_parse_operand:Nw #1 #2
+ {
+ \if_catcode:w \tex_relax:D #2
+ \if_meaning:w \tex_relax:D #2
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_parse_operand_relax:NN
+ \else:
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_parse_operand_register:NN
+ \fi:
\else:
- \if_int_compare:w #3 < \c_zero
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_use_small:w
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #2 \exp_stop_f:
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_parse_operand_digit:NN
\else:
- \exp_after:wN \exp_after:wN \exp_after:wN \fp_use_none:w
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_parse_operand_other:NN
\fi:
\fi:
- #2 e #3 \q_stop
+ #1 #2
}
-\cs_new:Npn \fp_use_none:w #1 e #2 \q_stop {#1}
-\cs_new:Npn \fp_use_small:w #1 . #2 e #3 \q_stop
+\group_begin:
+\char_set_catcode_other:N \P
+\char_set_catcode_other:N \T
+\tl_to_lowercase:n
{
- 0 .
- \prg_replicate:nn { -#3 - 1 } { 0 }
- #1#2
+ \group_end:
+ \cs_new:Npn \__fp_parse_operand_register:NN #1#2
+ {
+ \exp_after:wN \__fp_parse_infix_after_operand:NwN
+ \exp_after:wN #1
+ \tex_romannumeral:D -`0
+ \exp_after:wN \__fp_parse_operand_register_aux:www
+ \tex_the:D
+ \exp_after:wN #2
+ \exp_after:wN P
+ \exp_after:wN T
+ \exp_after:wN \q_stop
+ \__int_value:w \__fp_parse_exponent:N
+ }
+ \cs_new:Npn \__fp_parse_operand_register_aux:www #1 PT #2 \q_stop #3 ;
+ { \__fp_parse:n { #1 e #3 } }
+ }
+\cs_new:Npn \__fp_parse_operand_relax:NN #1#2
+ {
+ \__fp_parse_operand_relax_aux:wwnw
+ #2 \s__fp_mark
+ {
+ \__fp_exp_after_o:nw
+ {
+ \tex_romannumeral:D -`0
+ \exp_after:wN \__fp_parse_infix:NN
+ \exp_after:wN #1 \tex_romannumeral:D \__fp_parse_expand:w
+ }
+ \s__fp
+ }
+ \s__fp #2
+ {
+ \__fp_error:n { Premature~end~in~fp~expression. }
+ \exp_after:wN \c_nan_fp
+ \tex_romannumeral:D -`0
+ \__fp_parse_infix:NN #1
+ \s__fp_mark
+ }
+ \s__fp_mark
+ {
+ \__fp_error:n { Erroneous~variable~#2 used! }
+ \exp_after:wN \c_nan_fp
+ \tex_romannumeral:D -`0
+ \exp_after:wN \__fp_parse_infix:NN
+ \exp_after:wN #1
+ \tex_romannumeral:D \__fp_parse_expand:w
+ }
+ \s__fp_mark \s__fp_stop
}
-\cs_new:Npn \fp_use_large:w #1 . #2 e #3 \q_stop
+\cs_new:Npn \__fp_parse_operand_relax_aux:wwnw
+ #1 \s__fp #2 \s__fp_mark #3 #4 \s__fp_mark \s__fp_stop { #3 }
+\cs_new:Npn \__fp_parse_operand_other:NN #1 #2
{
- \if_int_compare:w #3 < \c_ten
- \exp_after:wN \fp_use_large_aux_i:w
+ \if_int_compare:w
+ \__int_eval:w \tex_uccode:D `#2 / 26 = \c_three
+ \exp_after:wN \__fp_parse_operand_other_word_aux:Nw
+ \exp_after:wN #1
+ \tex_romannumeral:D
+ \exp_after:wN \__fp_parse_letters:NN
+ \exp_after:wN #2
+ \tex_romannumeral:D
\else:
- \exp_after:wN \fp_use_large_aux_ii:w
+ \exp_after:wN \__fp_parse_operand_other_prefix_aux:NNN
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \cs:w __fp_parse_prefix_#2:Nw \exp_after:wN \cs_end:
+ \tex_romannumeral:D
\fi:
- #1#2 e #3 \q_stop
+ \__fp_parse_expand:w
}
-\cs_new:Npn \fp_use_large_aux_i:w #1#2 e #3 \q_stop
+
+\cs_new:Npn \__fp_parse_letters:NN #1#2
{
- #1
- \use:c { fp_use_large_aux_ #3 :w } #2 \q_stop
- }
-\cs_new:cpn { fp_use_large_aux_1:w } #1#2 \q_stop { #1 . #2 }
-\cs_new:cpn { fp_use_large_aux_2:w } #1#2#3 \q_stop
- { #1#2 . #3 }
-\cs_new:cpn { fp_use_large_aux_3:w } #1#2#3#4 \q_stop
- { #1#2#3 . #4 }
-\cs_new:cpn { fp_use_large_aux_4:w } #1#2#3#4#5 \q_stop
- { #1#2#3#4 . #5 }
-\cs_new:cpn { fp_use_large_aux_5:w } #1#2#3#4#5#6 \q_stop
- { #1#2#3#4#5 . #6 }
-\cs_new:cpn { fp_use_large_aux_6:w } #1#2#3#4#5#6#7 \q_stop
- { #1#2#3#4#5#6 . #7 }
-\cs_new:cpn { fp_use_large_aux_7:w } #1#2#3#4#5#6#7#8 \q_stop
- { #1#2#3#4#6#7 . #8 }
-\cs_new:cpn { fp_use_large_aux_8:w } #1#2#3#4#5#6#7#8#9 \q_stop
- { #1#2#3#4#5#6#7#8 . #9 }
-\cs_new:cpn { fp_use_large_aux_9:w } #1 \q_stop { #1 . }
-\cs_new:Npn \fp_use_large_aux_ii:w #1 e #2 \q_stop
+ \exp_after:wN \c_zero
+ \exp_after:wN #1
+ \tex_romannumeral:D
+ \if_int_compare:w
+ \if_catcode:w \tex_relax:D #2
+ \c_zero
+ \else:
+ \__int_eval:w \tex_uccode:D `#2 / 26
+ \fi:
+ = \c_three
+ \exp_after:wN \__fp_parse_letters:NN
+ \exp_after:wN #2
+ \tex_romannumeral:D
+ \exp_after:wN \__fp_parse_expand:w
+ \else:
+ \exp_after:wN \c_zero
+ \exp_after:wN ;
+ \exp_after:wN #2
+ \fi:
+ }
+\cs_new:Npn \__fp_parse_operand_other_word_aux:Nw #1 #2;
{
- #1
- \prg_replicate:nn { #2 - 9 } { 0 }
- .
+ \cs_if_exist_use:cF { __fp_parse_word_#2:N }
+ {
+ \__msg_expandable_error:n { Unknown~word~#2. }
+ \exp_after:wN \c_nan_fp
+ \tex_romannumeral:D -`0
+ \__fp_parse_infix:NN
+ }
+ #1
}
-\cs_new_eq:NN \fp_if_exist:NTF \cs_if_exist:NTF
-\cs_new_eq:NN \fp_if_exist:NT \cs_if_exist:NT
-\cs_new_eq:NN \fp_if_exist:NF \cs_if_exist:NF
-\cs_new_eq:NN \fp_if_exist_p:N \cs_if_exist_p:N
-\cs_new_eq:NN \fp_if_exist:cTF \cs_if_exist:cTF
-\cs_new_eq:NN \fp_if_exist:cT \cs_if_exist:cT
-\cs_new_eq:NN \fp_if_exist:cF \cs_if_exist:cF
-\cs_new_eq:NN \fp_if_exist_p:c \cs_if_exist_p:c
-\cs_new:Npn \fp_to_dim:N #1 { \fp_use:N #1 pt }
-\cs_generate_variant:Nn \fp_to_dim:N { c }
-\cs_new:Npn \fp_to_int:N #1
- { \exp_after:wN \fp_to_int_aux:w #1 \q_stop }
-\cs_generate_variant:Nn \fp_to_int:N { c }
-\cs_new:Npn \fp_to_int_aux:w #1#2 e #3 \q_stop
+\cs_new_eq:NN \s__fp_unknown \tex_relax:D
+\cs_new:Npn \__fp_parse_operand_other_prefix_aux:NNN #1#2#3
{
- \if:w #1 -
- -
+ \if_meaning:w \tex_relax:D #3
+ \exp_after:wN \__fp_parse_operand_other_prefix_unknown:NNN
+ \exp_after:wN #2
\fi:
- \if_int_compare:w #3 < \c_zero
- \exp_after:wN \fp_to_int_small:w
- \else:
- \exp_after:wN \fp_to_int_large:w
- \fi:
- #2 e #3 \q_stop
+ #3 #1
+ }
+\cs_new:Npn \__fp_parse_operand_other_prefix_unknown:NNN #1#2#3
+ {
+ \cs_if_exist:cTF { __fp_parse_infix_#1:N }
+ {
+ \__fp_error:n { Missing~number~before~'#1'. }
+ \exp_after:wN \c_nan_fp
+ \tex_romannumeral:D -`0
+ \__fp_parse_infix:NN #3 #1
+ }
+ {
+ \__fp_error:n { Unknown~symbol~#1~ignored. }
+ \__fp_parse_operand:Nw #3
+ }
}
-\cs_new:Npn \fp_to_int_small:w #1 . #2 e #3 \q_stop
+\cs_new:Npn \__fp_parse_operand_digit:NN #1
{
- \if_int_compare:w #3 > \c_one
+ \exp_after:wN \__fp_parse_infix_after_operand:NwN
+ \exp_after:wN #1
+ \tex_romannumeral:D -`0
+ \exp_after:wN \__fp_sanitize:wN
+ \int_use:N \__int_eval:w \c_zero \__fp_parse_trim_zeros:N
+ }
+\cs_new:Npn \__fp_parse_trim_zeros:N #1
+ {
+ \if:w 0 #1
+ \exp_after:wN \__fp_parse_trim_zeros:N
+ \tex_romannumeral:D
\else:
- \if_int_compare:w #1 < \c_five
- 0
+ \if:w . #1
+ \exp_after:wN \__fp_parse_strim_zeros:N
+ \tex_romannumeral:D
\else:
- 1
+ \__fp_parse_trim_end:w #1
\fi:
\fi:
+ \__fp_parse_expand:w
}
-\cs_new:Npn \fp_to_int_large:w #1 . #2 e #3 \q_stop
+\cs_new:Npn \__fp_parse_trim_end:w #1 \fi: \fi: \__fp_parse_expand:w
{
- \if_int_compare:w #3 < \c_ten
- \exp_after:wN \fp_to_int_large_aux_i:w
+ \fi:
+ \fi:
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f:
+ \exp_after:wN \__fp_parse_large:N
\else:
- \exp_after:wN \fp_to_int_large_aux_ii:w
+ \exp_after:wN \__fp_parse_zero:
\fi:
- #1#2 e #3 \q_stop
+ #1
}
-\cs_new:Npn \fp_to_int_large_aux_i:w #1#2 e #3 \q_stop
- { \use:c { fp_to_int_large_aux_ #3 :w } #2 \q_stop {#1} }
-\cs_new:cpn { fp_to_int_large_aux_1:w } #1#2 \q_stop
- { \fp_to_int_large_aux:nnn { #2 0 } {#1} }
-\cs_new:cpn { fp_to_int_large_aux_2:w } #1#2#3 \q_stop
- { \fp_to_int_large_aux:nnn { #3 00 } {#1#2} }
-\cs_new:cpn { fp_to_int_large_aux_3:w } #1#2#3#4 \q_stop
- { \fp_to_int_large_aux:nnn { #4 000 } {#1#2#3} }
-\cs_new:cpn { fp_to_int_large_aux_4:w } #1#2#3#4#5 \q_stop
- { \fp_to_int_large_aux:nnn { #5 0000 } {#1#2#3#4} }
-\cs_new:cpn { fp_to_int_large_aux_5:w } #1#2#3#4#5#6 \q_stop
- { \fp_to_int_large_aux:nnn { #6 00000 } {#1#2#3#4#5} }
-\cs_new:cpn { fp_to_int_large_aux_6:w } #1#2#3#4#5#6#7 \q_stop
- { \fp_to_int_large_aux:nnn { #7 000000 } {#1#2#3#4#5#6} }
-\cs_new:cpn { fp_to_int_large_aux_7:w } #1#2#3#4#5#6#7#8 \q_stop
- { \fp_to_int_large_aux:nnn { #8 0000000 } {#1#2#3#4#5#6#7} }
-\cs_new:cpn { fp_to_int_large_aux_8:w } #1#2#3#4#5#6#7#8#9 \q_stop
- { \fp_to_int_large_aux:nnn { #9 00000000 } {#1#2#3#4#5#6#7#8} }
-\cs_new:cpn { fp_to_int_large_aux_9:w } #1 \q_stop {#1}
-\cs_new:Npn \fp_to_int_large_aux:nnn #1#2#3
+\cs_new:Npn \__fp_parse_strim_zeros:N #1
{
- \if_int_compare:w #1 < \c_five_hundred_million
- #3#2
+ \if:w 0 #1
+ - \c_one
+ \exp_after:wN \__fp_parse_strim_zeros:N
+ \tex_romannumeral:D
\else:
- \int_value:w \int_eval:w #3#2 + 1 \int_eval_end:
+ \__fp_parse_strim_end:w #1
\fi:
+ \__fp_parse_expand:w
}
-\cs_new:Npn \fp_to_int_large_aux_ii:w #1 e #2 \q_stop
+\cs_new:Npn \__fp_parse_strim_end:w #1 \fi: \__fp_parse_expand:w
{
- #1
- \prg_replicate:nn { #2 - 9 } { 0 }
- }
-\cs_new:Npn \fp_to_tl:N #1
- { \exp_after:wN \fp_to_tl_aux:w #1 \q_stop }
-\cs_generate_variant:Nn \fp_to_tl:N { c }
-\cs_new:Npn \fp_to_tl_aux:w #1#2 e #3 \q_stop
- {
- \if:w #1 -
- -
\fi:
- \if_int_compare:w #3 < \c_zero
- \exp_after:wN \fp_to_tl_small:w
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f:
+ \exp_after:wN \__fp_parse_small:N
\else:
- \exp_after:wN \fp_to_tl_large:w
+ \exp_after:wN \__fp_parse_zero:
\fi:
- #2 e #3 \q_stop
+ #1
}
-\cs_new:Npn \fp_to_tl_large:w #1 e #2 \q_stop
+\cs_new:Npn \__fp_parse_zero:
{
- \if_int_compare:w #2 < \c_ten
- \exp_after:wN \fp_to_tl_large_aux_i:w
- \else:
- \exp_after:wN \fp_to_tl_large_aux_ii:w
- \fi:
- #1 e #2 \q_stop
+ \exp_after:wN ; \exp_after:wN 1
+ \__int_value:w \__fp_parse_exponent:N
}
-\cs_new:Npn \fp_to_tl_large_aux_i:w #1 e #2 \q_stop
- { \use:c { fp_to_tl_large_ #2 :w } #1 \q_stop }
-\cs_new:Npn \fp_to_tl_large_aux_ii:w #1 . #2 e #3 \q_stop
+\cs_new:Npn \__fp_parse_small:N #1
{
- #1
- \fp_to_tl_large_zeros:NNNNNNNNN #2
- e #3
+ \exp_after:wN \__fp_parse_pack_leading:NNNNNww
+ \int_use:N \__int_eval:w 1 \token_to_str:N #1
+ \exp_after:wN \__fp_parse_small_leading:wwNN
+ \__int_value:w 1
+ \exp_after:wN \__fp_parse_digits_vii:N
+ \tex_romannumeral:D \__fp_parse_expand:w
}
-\cs_new:cpn { fp_to_tl_large_0:w } #1 . #2 \q_stop
+\cs_new:Npn \__fp_parse_small_leading:wwNN 1 #1 ; #2; #3 #4
{
- #1
- \fp_to_tl_large_zeros:NNNNNNNNN #2
+ #1 #2
+ \exp_after:wN \__fp_parse_pack_trailing:NNNNNNww
+ \exp_after:wN \c_zero
+ \int_use:N \__int_eval:w 1
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #4 \exp_stop_f:
+ \token_to_str:N #4
+ \exp_after:wN \__fp_parse_small_trailing:wwNN
+ \__int_value:w 1
+ \exp_after:wN \__fp_parse_digits_vi:N
+ \tex_romannumeral:D
+ \else:
+ 0000 0000 \__fp_parse_exponent:Nw #4
+ \fi:
+ \__fp_parse_expand:w
}
-\cs_new:cpn { fp_to_tl_large_1:w } #1 . #2#3 \q_stop
+\cs_new:Npn \__fp_parse_small_trailing:wwNN 1 #1 ; #2; #3 #4
{
- #1#2
- \fp_to_tl_large_zeros:NNNNNNNNN #3 0
+ #1 #2
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #4 \exp_stop_f:
+ \token_to_str:N #4
+ \exp_after:wN \__fp_parse_small_round:NN
+ \exp_after:wN #4
+ \tex_romannumeral:D
+ \else:
+ 0 \__fp_parse_exponent:Nw #4
+ \fi:
+ \__fp_parse_expand:w
}
-\cs_new:cpn { fp_to_tl_large_2:w } #1 . #2#3#4 \q_stop
+\cs_new:Npn \__fp_parse_pack_trailing:NNNNNNww #1 #2 #3#4#5#6 #7; #8 ;
{
- #1#2#3
- \fp_to_tl_large_zeros:NNNNNNNNN #4 00
+ \if_meaning:w 2 #2 + \c_one \fi:
+ ; #8 + #1 ; {#3#4#5#6} {#7};
}
-\cs_new:cpn { fp_to_tl_large_3:w } #1 . #2#3#4#5 \q_stop
+\cs_new:Npn \__fp_parse_pack_leading:NNNNNww #1 #2#3#4#5 #6; #7;
{
- #1#2#3#4
- \fp_to_tl_large_zeros:NNNNNNNNN #5 000
+ + #7
+ \if_meaning:w 2 #1 \__fp_parse_pack_carry:w \fi:
+ ; 0 {#2#3#4#5} {#6}
}
-\cs_new:cpn { fp_to_tl_large_4:w } #1 . #2#3#4#5#6 \q_stop
+\cs_new:Npn \__fp_parse_pack_carry:w \fi: ; 0 #1
+ { \fi: + \c_one ; 0 {1000} }
+\cs_new:Npn \__fp_parse_large:N #1
{
- #1#2#3#4#5
- \fp_to_tl_large_zeros:NNNNNNNNN #6 0000
+ \exp_after:wN \__fp_parse_large_leading:wwNN
+ \__int_value:w 1 \token_to_str:N #1
+ \exp_after:wN \__fp_parse_digits_vii:N
+ \tex_romannumeral:D \__fp_parse_expand:w
}
-\cs_new:cpn { fp_to_tl_large_5:w } #1 . #2#3#4#5#6#7 \q_stop
+\cs_new:Npn \__fp_parse_large_leading:wwNN 1 #1 ; #2; #3 #4
{
- #1#2#3#4#5#6
- \fp_to_tl_large_zeros:NNNNNNNNN #7 00000
+ + \c_eight - #3
+ \exp_after:wN \__fp_parse_pack_leading:NNNNNww
+ \int_use:N \__int_eval:w 1 #1
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #4 \exp_stop_f:
+ \exp_after:wN \__fp_parse_large_trailing:wwNN
+ \__int_value:w 1 \token_to_str:N #4
+ \exp_after:wN \__fp_parse_digits_vi:N
+ \tex_romannumeral:D
+ \else:
+ \if:w . #4
+ \exp_after:wN \__fp_parse_small_leading:wwNN
+ \__int_value:w 1
+ \cs:w
+ __fp_parse_digits_
+ \tex_romannumeral:D #3
+ :N \exp_after:wN
+ \cs_end:
+ \tex_romannumeral:D
+ \else:
+ #2
+ \exp_after:wN \__fp_parse_pack_trailing:NNNNNNww
+ \exp_after:wN \c_zero
+ \__int_value:w 1 0000 0000
+ \__fp_parse_exponent:Nw #4
+ \fi:
+ \fi:
+ \__fp_parse_expand:w
}
-\cs_new:cpn { fp_to_tl_large_6:w } #1 . #2#3#4#5#6#7#8 \q_stop
+\cs_new:Npn \__fp_parse_large_trailing:wwNN 1 #1 ; #2; #3 #4
{
- #1#2#3#4#5#6#7
- \fp_to_tl_large_zeros:NNNNNNNNN #8 000000
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #4 \exp_stop_f:
+ \exp_after:wN \__fp_parse_pack_trailing:NNNNNNww
+ \exp_after:wN \c_eight
+ \int_use:N \__int_eval:w 1 #1 \token_to_str:N #4
+ \exp_after:wN \__fp_parse_large_round:NN
+ \exp_after:wN #4
+ \tex_romannumeral:D
+ \else:
+ \exp_after:wN \__fp_parse_pack_trailing:NNNNNNww
+ \int_use:N \__int_eval:w \c_seven - #3 \exp_stop_f:
+ \int_use:N \__int_eval:w 1 #1
+ \if:w . #4
+ \exp_after:wN \__fp_parse_small_trailing:wwNN
+ \__int_value:w 1
+ \cs:w
+ __fp_parse_digits_
+ \tex_romannumeral:D #3
+ :N \exp_after:wN
+ \cs_end:
+ \tex_romannumeral:D
+ \else:
+ #2 0 \__fp_parse_exponent:Nw #4
+ \fi:
+ \fi:
+ \__fp_parse_expand:w
}
-\cs_new:cpn { fp_to_tl_large_7:w } #1 . #2#3#4#5#6#7#8#9 \q_stop
+\cs_new:Npn \__fp_parse_exponent:Nw #1 #2 \__fp_parse_expand:w
{
- #1#2#3#4#5#6#7#8
- \fp_to_tl_large_zeros:NNNNNNNNN #9 0000000
+ \exp_after:wN ;
+ \__int_value:w #2 \__fp_parse_exponent:N #1
}
-\cs_new:cpn { fp_to_tl_large_8:w } #1 .
+\cs_new:Npn \__fp_parse_exponent:N #1
{
- #1
- \use:c { fp_to_tl_large_8_aux:w }
+ \if:w e #1
+ \exp_after:wN \__fp_parse_exponent_ii:N
+ \tex_romannumeral:D
+ \else:
+ 0 \__fp_parse_return_semicolon:w #1
+ \fi:
+ \__fp_parse_expand:w
}
-\cs_new:cpn { fp_to_tl_large_8_aux:w } #1#2#3#4#5#6#7#8#9 \q_stop
+\cs_new:Npn \__fp_parse_exponent_ii:N #1
{
- #1#2#3#4#5#6#7#8
- \fp_to_tl_large_zeros:NNNNNNNNN #9 00000000
+ \if_int_compare:w \if_catcode:w \tex_relax:D #1
+ \c_zero \else: `#1 \fi: > `9 \exp_stop_f:
+ 0 \exp_after:wN ; \exp_after:wN e
+ \else:
+ \exp_after:wN \__fp_parse_exponent_sign:N
+ \fi:
+ #1
}
-\cs_new:cpn { fp_to_tl_large_9:w } #1 . #2 \q_stop {#1#2}
-\cs_new:Npn \fp_to_tl_small:w #1 e #2 \q_stop
+\cs_new:Npn \__fp_parse_exponent_sign:N #1
{
- \if_int_compare:w #2 = \c_minus_one
- \exp_after:wN \fp_to_tl_small_one:w
+ \if:w + \if:w - #1 + \fi: \token_to_str:N #1
+ \exp_after:wN \__fp_parse_exponent_sign:N
+ \tex_romannumeral:D \exp_after:wN \__fp_parse_expand:w
\else:
- \if_int_compare:w #2 = -\c_two
- \exp_after:wN \exp_after:wN \exp_after:wN \fp_to_tl_small_two:w
- \else:
- \exp_after:wN \exp_after:wN \exp_after:wN \fp_to_tl_small_aux:w
- \fi:
+ \exp_after:wN \__fp_parse_exponent_body:N
+ \exp_after:wN #1
\fi:
- #1 e #2 \q_stop
}
-\cs_new:Npn \fp_to_tl_small_one:w #1 . #2 e #3 \q_stop
+\cs_new:Npn \__fp_parse_exponent_body:N #1
{
- \if_int_compare:w \fp_use_ix:NNNNNNNNN #2 > \c_four
- \if_int_compare:w
- \int_eval:w #1 \fp_use_i_to_iix:NNNNNNNNN #2 + 1
- < \c_one_thousand_million
- 0.
- \exp_after:wN \fp_to_tl_small_zeros:NNNNNNNNN
- \int_value:w \int_eval:w
- #1 \fp_use_i_to_iix:NNNNNNNNN #2 + 1
- \int_eval_end:
- \else:
- 1
- \fi:
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f:
+ \token_to_str:N #1
+ \exp_after:wN \__fp_parse_exponent_digits:N
+ \tex_romannumeral:D
\else:
- 0. #1
- \fp_to_tl_small_zeros:NNNNNNNNN #2
+ \__fp_parse_exponent_keep:NTF #1
+ { \__fp_parse_return_semicolon:w #1 }
+ {
+ \exp_after:wN ;
+ \tex_romannumeral:D
+ }
\fi:
+ \__fp_parse_expand:w
}
-\cs_new:Npn \fp_to_tl_small_two:w #1 . #2 e #3 \q_stop
+\cs_new:Npn \__fp_parse_exponent_digits:N #1
{
- \if_int_compare:w \fp_use_iix_ix:NNNNNNNNN #2 > \c_forty_four
- \if_int_compare:w
- \int_eval:w #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
- \int_value:w \int_eval:w
- #1 \fp_use_i_to_vii:NNNNNNNNN #2 0 + \c_ten
- \int_eval_end:
- \else:
- 0.1
- \fi:
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f:
+ \token_to_str:N #1
+ \exp_after:wN \__fp_parse_exponent_digits:N
+ \tex_romannumeral:D
\else:
- 0.0
- #1
- \fp_to_tl_small_zeros:NNNNNNNNN #2
+ \__fp_parse_return_semicolon:w #1
\fi:
+ \__fp_parse_expand:w
}
-\cs_new:Npn \fp_to_tl_small_aux:w #1 . #2 e #3 \q_stop
+\prg_new_conditional:Npnn \__fp_parse_exponent_keep:N #1 { TF }
{
- #1
- \fp_to_tl_large_zeros:NNNNNNNNN #2
- e #3
- }
-\cs_new:Npn \fp_to_tl_large_zeros:NNNNNNNNN #1#2#3#4#5#6#7#8#9
- {
- \if_int_compare:w #9 = \c_zero
- \if_int_compare:w #8 = \c_zero
- \if_int_compare:w #7 = \c_zero
- \if_int_compare:w #6 = \c_zero
- \if_int_compare:w #5 = \c_zero
- \if_int_compare:w #4 = \c_zero
- \if_int_compare:w #3 = \c_zero
- \if_int_compare:w #2 = \c_zero
- \if_int_compare:w #1 = \c_zero
- \else:
- . #1
- \fi:
- \else:
- . #1#2
- \fi:
- \else:
- . #1#2#3
- \fi:
- \else:
- . #1#2#3#4
- \fi:
- \else:
- . #1#2#3#4#5
- \fi:
- \else:
- . #1#2#3#4#5#6
- \fi:
+ \if_catcode:w \tex_relax:D #1
+ \if_meaning:w \tex_relax:D #1
+ \if_int_compare:w \pdftex_strcmp:D { \s__fp } { #1 } = \c_zero
+ 0 \__fp_error:n { Cannot~use~floating~point~after~'e'. }
+ \prg_return_true:
\else:
- . #1#2#3#4#5#6#7
+ 0 \__fp_error:n { Erroneous~variable~#1 used. }
+ \prg_return_false:
\fi:
\else:
- . #1#2#3#4#5#6#7#8
- \fi:
- \else:
- . #1#2#3#4#5#6#7#8#9
- \fi:
- }
-\cs_new:Npn \fp_to_tl_small_zeros:NNNNNNNNN #1#2#3#4#5#6#7#8#9
- {
- \if_int_compare:w #9 = \c_zero
- \if_int_compare:w #8 = \c_zero
- \if_int_compare:w #7 = \c_zero
- \if_int_compare:w #6 = \c_zero
- \if_int_compare:w #5 = \c_zero
- \if_int_compare:w #4 = \c_zero
- \if_int_compare:w #3 = \c_zero
- \if_int_compare:w #2 = \c_zero
- \if_int_compare:w #1 = \c_zero
- \else:
- #1
- \fi:
- \else:
- #1#2
- \fi:
- \else:
- #1#2#3
- \fi:
- \else:
- #1#2#3#4
- \fi:
- \else:
- #1#2#3#4#5
- \fi:
- \else:
- #1#2#3#4#5#6
- \fi:
+ \if_int_compare:w
+ \pdftex_strcmp:D { \__int_value:w #1 } { \tex_the:D #1 }
+ = \c_zero
+ \__int_value:w #1
\else:
- #1#2#3#4#5#6#7
+ 0 \__fp_error:n { Cannot~use~a~dimension~(#1)~after~'e'. }
\fi:
- \else:
- #1#2#3#4#5#6#7#8
+ \prg_return_false:
\fi:
\else:
- #1#2#3#4#5#6#7#8#9
+ 0 \__fp_error:n { Missing~exponent~after~'e'. }
+ \prg_return_true:
\fi:
}
-\cs_new:Npn \fp_use_iix_ix:NNNNNNNNN #1#2#3#4#5#6#7#8#9 {#8#9}
-\cs_new:Npn \fp_use_ix:NNNNNNNNN #1#2#3#4#5#6#7#8#9 {#9}
-\cs_new:Npn \fp_use_i_to_vii:NNNNNNNNN #1#2#3#4#5#6#7#8#9
- {#1#2#3#4#5#6#7}
-\cs_new:Npn \fp_use_i_to_iix:NNNNNNNNN #1#2#3#4#5#6#7#8#9
- {#1#2#3#4#5#6#7#8}
-\cs_new_protected_nopar:Npn \fp_round_figures:Nn
- { \fp_round_figures_aux:NNn \tl_set:Nn }
-\cs_generate_variant:Nn \fp_round_figures:Nn { c }
-\cs_new_protected_nopar:Npn \fp_ground_figures:Nn
- { \fp_round_figures_aux:NNn \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_ground_figures:Nn { c }
-\cs_new_protected:Npn \fp_round_figures_aux:NNn #1#2#3
+\cs_new:Npn \__fp_cfs_round_loop:N #1
{
- \group_begin:
- \fp_read:N #2
- \int_set:Nn \l_fp_round_target_int { #3 - 1 }
- \if_int_compare:w \l_fp_round_target_int < \c_ten
- \exp_after:wN \fp_round:
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f:
+ + \c_one
+ \if:w 0 #1
+ \exp_after:wN \__fp_cfs_round_loop:N
+ \tex_romannumeral:D
+ \else:
+ \exp_after:wN \__fp_cfs_round_up:N
+ \tex_romannumeral:D
\fi:
- \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2
- {
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- -
- \else:
- +
- \fi:
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_input_a_decimal_int
- e
- \int_use:N \l_fp_input_a_exponent_int
- }
- }
- \fp_tmp:w
+ \else:
+ \__fp_parse_return_semicolon:w \c_zero #1
+ \fi:
+ \__fp_parse_expand:w
}
-\cs_new_protected_nopar:Npn \fp_round_places:Nn
- { \fp_round_places_aux:NNn \tl_set:Nn }
-\cs_generate_variant:Nn \fp_round_places:Nn { c }
-\cs_new_protected_nopar:Npn \fp_ground_places:Nn
- { \fp_round_places_aux:NNn \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_ground_places:Nn { c }
-\cs_new_protected:Npn \fp_round_places_aux:NNn #1#2#3
+\cs_new:Npn \__fp_cfs_round_up:N #1
{
- \group_begin:
- \fp_read:N #2
- \int_set:Nn \l_fp_round_target_int
- { #3 + \l_fp_input_a_exponent_int }
- \if_int_compare:w \l_fp_round_target_int < \c_ten
- \exp_after:wN \fp_round:
- \fi:
- \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2
- {
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- -
- \else:
- +
- \fi:
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_input_a_decimal_int
- e
- \int_use:N \l_fp_input_a_exponent_int
- }
- }
- \fp_tmp:w
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f:
+ + 1
+ \exp_after:wN \__fp_cfs_round_up:N
+ \tex_romannumeral:D
+ \else:
+ \__fp_parse_return_semicolon:w \c_one #1
+ \fi:
+ \__fp_parse_expand:w
+ }
+\cs_new:Npn \__fp_parse_large_round:NN #1#2
+ {
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #2 \exp_stop_f:
+ +
+ \exp_after:wN \__fp_round_s:NNNw
+ \exp_after:wN 0
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \int_use:N \__int_eval:w
+ \exp_after:wN \__fp_parse_large_round_after:wNN
+ \int_use:N \__int_eval:w \c_one
+ \exp_after:wN \__fp_cfs_round_loop:N
+ \else: %^^A could be dot, or e, or other
+ \exp_after:wN \__fp_parse_large_round_dot_test:NNw
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \fi:
}
-\cs_new_protected_nopar:Npn \fp_round:
+\cs_new:Npn \__fp_parse_large_round_dot_test:NNw #1#2
{
- \bool_set_false:N \l_fp_round_carry_bool
- \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
- \fp_round_aux:NNNNNNNNN \int_use:N \l_fp_input_a_decimal_int
+ \if:w . #2
+ \exp_after:wN \__fp_parse_small_round:NN
+ \exp_after:wN #1
+ \tex_romannumeral:D
+ \else:
+ \__fp_parse_exponent:Nw #2
+ \fi:
+ \__fp_parse_expand:w
}
-\cs_new_protected:Npn \fp_round_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9
+\cs_new:Npn \__fp_parse_large_round_after:wNN #1 ; #2 #3
{
- \fp_round_loop:N #9#8#7#6#5#4#3#2#1
- \bool_if:NT \l_fp_round_carry_bool
- { \tex_advance:D \l_fp_input_a_integer_int \c_one }
- \l_fp_input_a_decimal_int \l_fp_round_decimal_tl \scan_stop:
- \if_int_compare:w \l_fp_input_a_integer_int < \c_ten
+ \if:w . #3
+ \exp_after:wN \__fp_parse_large_round_after_ii:wN
+ \int_use:N \__int_eval:w #1 +
+ \c_zero * \__int_eval:w \c_zero
+ \exp_after:wN \__fp_cfs_round_loop:N
+ \tex_romannumeral:D \exp_after:wN \__fp_parse_expand:w
+ \else:
+ + #2
+ \exp_after:wN ;
+ \int_use:N \__int_eval:w #1 +
+ \exp_after:wN \__fp_parse_exponent:N
+ \exp_after:wN #3
+ \fi:
+ }
+\cs_new:Npn \__fp_parse_large_round_after_ii:wN #1 ; #2
+ {
+ + #2
+ \exp_after:wN ;
+ \int_use:N \__int_eval:w #1 +
+ \__fp_parse_exponent:N
+ }
+\cs_new:Npn \__fp_parse_small_round:NN #1#2
+ {
+ \if_int_compare:w \c_nine < 1 \token_to_str:N #2 \exp_stop_f:
+ +
+ \exp_after:wN \__fp_round_s:NNNw
+ \exp_after:wN 0
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \int_use:N \__int_eval:w
+ \exp_after:wN \__fp_parse_small_round_after:wN
+ \int_use:N \__int_eval:w \c_zero
+ \exp_after:wN \__fp_cfs_round_loop:N
+ \tex_romannumeral:D
\else:
- \l_fp_input_a_integer_int \c_one
- \tex_divide:D \l_fp_input_a_decimal_int \c_ten
- \tex_advance:D \l_fp_input_a_exponent_int \c_one
+ \__fp_parse_exponent:Nw #2
\fi:
+ \__fp_parse_expand:w
}
-\cs_new_protected:Npn \fp_round_loop:N #1
+\cs_new:Npn \__fp_parse_small_round_after:wN #1; #2
{
- \if_int_compare:w \l_fp_round_position_int < \l_fp_round_target_int
- \bool_if:NTF \l_fp_round_carry_bool
- { \l_fp_internal_int \int_eval:w #1 + \c_one \scan_stop: }
- { \l_fp_internal_int \int_eval:w #1 \scan_stop: }
- \if_int_compare:w \l_fp_internal_int = \c_ten
- \l_fp_internal_int \c_zero
+ + #2 \exp_after:wN ;
+ \__int_value:w \__fp_parse_exponent:N
+ }
+\cs_new:Npn \__fp_parse:n #1
+ {
+ \tex_romannumeral:D
+ \exp_after:wN \__fp_parse_after:ww
+ \tex_romannumeral:D
+ \__fp_parse_until:Nw \c_minus_one
+ \__fp_parse_expand:w #1 \s__fp_mark
+ \s__fp_stop
+ }
+\cs_new:Npn \__fp_parse_after:ww #1@ #2 \s__fp_stop
+ {
+ \c_zero #1
+ }
+\cs_new:Npn \__fp_parse_until:Nw #1
+ {
+ -`0
+ \exp_after:wN \__fp_parse_until_test:NwN
+ \exp_after:wN #1
+ \tex_romannumeral:D -`0
+ \exp_after:wN \__fp_parse_operand:Nw
+ \exp_after:wN #1
+ \tex_romannumeral:D
+ }
+\cs_new:Npn \__fp_parse_until_test:NwN #1 #2 @ #3 { #3 #1 #2 @ }
+\cs_new:Npn \__fp_parse_stop_until:N #1 { }
+\cs_new:Npn \__fp_parse_infix_after_operand:NwN #1 #2;
+ {
+ \__fp_exp_after_f:nw { \__fp_parse_infix:NN #1 }
+ #2;
+ }
+\group_begin:
+ \char_set_catcode_letter:N \*
+ \cs_new:Npn \__fp_parse_infix:NN #1 #2
+ {
+ \if_catcode:w \tex_relax:D #2
+ \if_int_compare:w
+ \pdftex_strcmp:D { \s__fp_mark } { #2 }
+ = \c_zero
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_parse_infix_end:N
+ \else:
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_parse_infix_juxtapose:N
+ \fi:
+ \else:
+ \if_int_compare:w
+ \__int_eval:w \tex_uccode:D `#2 / 26
+ = \c_three
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_parse_infix_juxtapose:N
+ \else:
+ \exp_after:wN \__fp_parse_infix_check:NNN
+ \cs:w
+ __fp_parse_infix_#2:N
+ \exp_after:wN \exp_after:wN \exp_after:wN
+ \cs_end:
+ \fi:
+ \fi:
+ #1
+ #2
+ }
+ \cs_new:Npn \__fp_parse_infix_check:NNN #1#2#3
+ {
+ \if_meaning:w \tex_relax:D #1
+ \__msg_expandable_error:n { Missing~*~inserted. }
+ \exp_after:wN \__fp_parse_infix_*:N
+ \exp_after:wN #2
+ \exp_after:wN #3
\else:
- \bool_set_false:N \l_fp_round_carry_bool
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \tex_romannumeral:D \exp_after:wN \__fp_parse_expand:w
\fi:
- \tl_set:Nx \l_fp_round_decimal_tl
- { \int_use:N \l_fp_internal_int \l_fp_round_decimal_tl }
+ }
+\group_end:
+\cs_new:Npn \__fp_parse_apply_binary:NwNwN #1 #2#3@ #4 #5#6@ #7
+ {
+ \exp_after:wN \__fp_parse_until_test:NwN
+ \exp_after:wN #1
+ \tex_romannumeral:D -`0
+ \cs:w
+ __fp
+ \__fp_type_from_scan:N #2
+ \__fp_type_from_scan:N #5
+ _ #4 _o:ww
+ \cs_end:
+ #2#3 #5#6
+ \tex_romannumeral:D -`0 #7 #1
+ }
+\cs_new:Npn \__fp_parse_apply_unary_array:NNwN #1#2#3@#4
+ {
+ #2 #3 @
+ \tex_romannumeral:D -`0 #4 #1
+ }
+\cs_new:Npn \__fp_parse_apply_unary:NNwN #1#2#3@#4
+ {
+ #2 #3
+ \tex_romannumeral:D -`0 #4 #1
+ }
+\cs_new:Npn \__fp_parse_unary_type:N #1
+ { \__fp_type_from_scan:N #1 :w \cs_end: #1 }
+\cs_set_protected:Npn \__fp_tmp:w #1 #2
+ {
+ \cs_new_nopar:cpn { __fp_parse_word_#1:N }
+ { \exp_after:wN #2 \tex_romannumeral:D -`0 \__fp_parse_infix:NN }
+ }
+\__fp_tmp:w { inf } \c_inf_fp
+\__fp_tmp:w { nan } \c_nan_fp
+\__fp_tmp:w { pi } \c_pi_fp
+\__fp_tmp:w { deg } \c_one_degree_fp
+\__fp_tmp:w { true } \c_one_fp
+\__fp_tmp:w { false } \c_zero_fp
+\__fp_tmp:w { pt } \c_one_fp
+\cs_set_protected:Npn \__fp_tmp:w #1 #2
+ {
+ \cs_new_nopar:cpn { __fp_parse_word_#1:N }
+ {
+ \__fp_exp_after_f:nw { \__fp_parse_infix:NN }
+ \s__fp \__fp_chk:w 10 #2 ;
+ }
+ }
+\__fp_tmp:w {in} { {2} {7227} {0000} {0000} {0000} }
+\__fp_tmp:w {pc} { {2} {1200} {0000} {0000} {0000} }
+\__fp_tmp:w {cm} { {2} {2845} {2755} {9055} {1181} }
+\__fp_tmp:w {mm} { {1} {2845} {2755} {9055} {1181} }
+\__fp_tmp:w {dd} { {1} {1070} {0085} {6496} {0630} }
+\__fp_tmp:w {cc} { {2} {1284} {0102} {7795} {2756} }
+\__fp_tmp:w {nd} { {1} {1066} {9783} {4645} {6693} }
+\__fp_tmp:w {nc} { {2} {1280} {3740} {1574} {8031} }
+\__fp_tmp:w {bp} { {1} {1003} {7500} {0000} {0000} }
+\__fp_tmp:w {sp} { {-4} {1525} {8789} {0625} {0000} }
+\tl_map_inline:nn { {em} {ex} }
+ {
+ \cs_new_nopar:cpn { __fp_parse_word_#1:N }
+ {
+ \exp_after:wN \dim_to_fp:n \exp_after:wN
+ { \dim_use:N \__dim_eval:w 1 #1 \exp_after:wN }
+ \tex_romannumeral:D -`0 \__fp_parse_infix:NN
+ }
+ }
+\tl_map_inline:nn { {abs} {cos} {cot} {exp} {ln} {sin} {tan} }
+ {
+ \cs_new:cpn { __fp_parse_word_#1:N } ##1
+ {
+ \exp_after:wN \__fp_parse_apply_unary:NNwN
+ \exp_after:wN ##1
+ \cs:w __fp_ #1 \exp_after:wN \__fp_parse_unary_type:N
+ \tex_romannumeral:D
+ \__fp_parse_until:Nw \c_fifteen
+ \__fp_parse_expand:w
+ }
+ }
+\cs_set_protected:Npn \__fp_tmp:w #1#2
+ {
+ \cs_new:Npn #1 ##1
+ {
+ \exp_after:wN \__fp_parse_apply_unary_array:NNwN
+ \exp_after:wN ##1
+ \exp_after:wN #2
+ \tex_romannumeral:D
+ \__fp_parse_until:Nw \c_sixteen \__fp_parse_expand:w
+ }
+ }
+\__fp_tmp:w \__fp_parse_word_max:N \__fp_max:w
+\__fp_tmp:w \__fp_parse_word_min:N \__fp_min:w
+ % \__fp_tmp:w \__fp_parse_word_mod:N \__fp_mod:w %^^A todo: not implemented!
+\cs_new:Npn \__fp_parse_word_round:N #1#2
+ {
+ \if_meaning:w + #2
+ \__fp_parse_round:Nw \__fp_round_to_pinf:NNN
\else:
- \tl_set:Nx \l_fp_round_decimal_tl { 0 \l_fp_round_decimal_tl }
- \if_int_compare:w \l_fp_round_position_int = \l_fp_round_target_int
- \if_int_compare:w #1 > \c_four
- \bool_set_true:N \l_fp_round_carry_bool
+ \if_meaning:w 0 #2
+ \__fp_parse_round:Nw \__fp_round_to_zero:NNN
+ \else:
+ \if_meaning:w - #2
+ \__fp_parse_round:Nw \__fp_round_to_ninf:NNN
\fi:
\fi:
\fi:
- \tex_advance:D \l_fp_round_position_int \c_minus_one
- \if_int_compare:w \l_fp_round_position_int > \c_minus_one
- \exp_after:wN \fp_round_loop:N
+ \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_until:Nw \c_sixteen \__fp_parse_expand:w #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:w #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:
+ \__fp_error:n { round()~expects~1~or~2~arguments. }
+ \exp_after:wN \c_nan_fp \tex_romannumeral:D
\fi:
+ -`0 #4 #1
}
-\cs_new_protected_nopar:Npn \fp_abs:N { \fp_abs_aux:NN \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gabs:N { \fp_abs_aux:NN \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_abs:N { c }
-\cs_generate_variant:Nn \fp_gabs:N { c }
-\cs_new_protected:Npn \fp_abs_aux:NN #1#2
+\cs_new_eq:cN { __fp_parse_prefix_+:Nw } \__fp_parse_operand:Nw
+\cs_set_protected:Npn \__fp_tmp:w #1#2
{
- \group_begin:
- \fp_read:N #2
- \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
- \cs_set_protected_nopar:Npx \fp_tmp:w
+ \cs_new:cpn { __fp_parse_prefix_#1:Nw } ##1
+ {
+ \exp_after:wN \__fp_parse_apply_unary:NNwN
+ \exp_after:wN ##1
+ \cs:w __fp_ #2 \exp_after:wN \__fp_parse_unary_type:N
+ \tex_romannumeral:D
+ \if_int_compare:w \c_twelve < ##1
+ \__fp_parse_until:Nw ##1
+ \else:
+ \__fp_parse_until:Nw \c_twelve
+ \fi:
+ \__fp_parse_expand:w
+ }
+ }
+\__fp_tmp:w - { neg }
+\__fp_tmp:w ! { not }
+\group_begin:
+ \char_set_catcode_letter:N \)
+ \cs_new:cpn { __fp_parse_prefix_(:Nw } #1
+ {
+ \exp_after:wN \__fp_parse_lparen_after:NwN
+ \exp_after:wN #1
+ \tex_romannumeral:D
+ \if_int_compare:w #1 = \c_sixteen
+ \__fp_parse_until:Nw \c_one
+ \else:
+ \__fp_parse_until:Nw \c_zero
+ \fi:
+ \__fp_parse_expand:w
+ }
+ \cs_new:Npn \__fp_parse_lparen_after:NwN #1#2@#3
+ {
+ \token_if_eq_meaning:NNTF #3 \__fp_parse_infix_):N
{
- \group_end:
- #1 \exp_not:N #2
- {
- +
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_input_a_decimal_int
- e
- \int_use:N \l_fp_input_a_exponent_int
- }
+ \__fp_parse_exp_after_array:wf #2 \s__fp_stop
+ \exp_after:wN \__fp_parse_infix:NN
+ \exp_after:wN #1
+ \tex_romannumeral:D \__fp_parse_expand:w
}
- \fp_tmp:w
- }
-\cs_new_protected_nopar:Npn \fp_neg:N { \fp_neg_aux:NN \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gneg:N { \fp_neg_aux:NN \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_neg:N { c }
-\cs_generate_variant:Nn \fp_gneg:N { c }
-\cs_new_protected:Npn \fp_neg_aux:NN #1#2
- {
- \group_begin:
- \fp_read:N #2
- \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
- \tl_set:Nx \l_fp_internal_tl
{
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- +
- \else:
- -
- \fi:
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_input_a_decimal_int
- e
- \int_use:N \l_fp_input_a_exponent_int
+ \__fp_error:n { Missing~')'~inserted. }
+ #2 @ \__fp_parse_stop_until:N #3
}
- \exp_after:wN \group_end: \exp_after:wN
- #1 \exp_after:wN #2 \exp_after:wN { \l_fp_internal_tl }
- }
-\cs_new_protected_nopar:Npn \fp_add:Nn { \fp_add_aux:NNn \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gadd:Nn { \fp_add_aux:NNn \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_add:Nn { c }
-\cs_generate_variant:Nn \fp_gadd:Nn { c }
-\cs_new_protected:Npn \fp_add_aux:NNn #1#2#3
- {
- \group_begin:
- \fp_read:N #2
- \fp_split:Nn b {#3}
- \fp_standardise:NNNN
- \l_fp_input_b_sign_int
- \l_fp_input_b_integer_int
- \l_fp_input_b_decimal_int
- \l_fp_input_b_exponent_int
- \fp_add_core:
- \fp_tmp:w #1#2
- }
-\cs_new_protected_nopar:Npn \fp_add_core:
- {
- \fp_level_input_exponents:
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_sign_int * \l_fp_input_b_sign_int
- > \c_zero
- \exp_after:wN \fp_add_sum:
- \else:
- \exp_after:wN \fp_add_difference:
- \fi:
- \l_fp_output_exponent_int \l_fp_input_a_exponent_int
- \fp_standardise:NNNN
- \l_fp_output_sign_int
- \l_fp_output_integer_int
- \l_fp_output_decimal_int
- \l_fp_output_exponent_int
- \cs_set_protected:Npx \fp_tmp:w ##1##2
+ }
+\group_end:
+\cs_new:Npn \__fp_parse_exp_after_array:wf #1
+ {
+ \cs:w __fp \__fp_type_from_scan:N #1 _exp_after_f:nw \cs_end:
+ { \__fp_parse_exp_after_array:wf }
+ #1
+ }
+\cs_new:Npn \__fp_stop_exp_after_f:nw #1#2 { }
+\cs_new:cpn {__fp_parse_prefix_.:Nw} #1
+ {
+ \exp_after:wN \__fp_parse_infix_after_operand:NwN
+ \exp_after:wN #1
+ \tex_romannumeral:D -`0
+ \exp_after:wN \__fp_sanitize:wN
+ \int_use:N \__int_eval:w \c_zero \__fp_parse_strim_zeros:N
+ }
+\cs_set_protected:Npn \__fp_tmp:w #1#2#3#4
+ {
+ \cs_new:Npn #1 ##1
{
- \group_end:
- ##1 ##2
- {
- \if_int_compare:w \l_fp_output_sign_int < \c_zero
- -
- \else:
- +
- \fi:
- \int_use:N \l_fp_output_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_output_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_output_exponent_int
- }
+ \if_int_compare:w ##1 < #3
+ \exp_after:wN @
+ \exp_after:wN \__fp_parse_apply_binary:NwNwN
+ \exp_after:wN #2
+ \tex_romannumeral:D
+ \__fp_parse_until:Nw #4
+ \exp_after:wN \__fp_parse_expand:w
+ \else:
+ \exp_after:wN @
+ \exp_after:wN \__fp_parse_stop_until:N
+ \exp_after:wN #1
+ \fi:
}
}
-\cs_new_protected_nopar:Npn \fp_add_sum:
- {
- \l_fp_output_sign_int \l_fp_input_a_sign_int
- \l_fp_output_integer_int
- \int_eval:w
- \l_fp_input_a_integer_int + \l_fp_input_b_integer_int
- \scan_stop:
- \l_fp_output_decimal_int
- \int_eval:w
- \l_fp_input_a_decimal_int + \l_fp_input_b_decimal_int
- \scan_stop:
- \if_int_compare:w \l_fp_output_decimal_int < \c_one_thousand_million
- \else:
- \tex_advance:D \l_fp_output_integer_int \c_one
- \tex_advance:D \l_fp_output_decimal_int -\c_one_thousand_million
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_add_difference:
- {
- \l_fp_output_integer_int
- \int_eval:w
- \l_fp_input_a_integer_int - \l_fp_input_b_integer_int
- \scan_stop:
- \l_fp_output_decimal_int
- \int_eval:w
- \l_fp_input_a_decimal_int - \l_fp_input_b_decimal_int
- \scan_stop:
- \if_int_compare:w \l_fp_output_decimal_int < \c_zero
- \tex_advance:D \l_fp_output_integer_int \c_minus_one
- \tex_advance:D \l_fp_output_decimal_int \c_one_thousand_million
- \fi:
- \if_int_compare:w \l_fp_output_integer_int < \c_zero
- \l_fp_output_sign_int \l_fp_input_b_sign_int
- \if_int_compare:w \l_fp_output_decimal_int = \c_zero
- \l_fp_output_integer_int -\l_fp_output_integer_int
+\group_begin:
+ \char_set_catcode_other:N \&
+ \__fp_tmp:w \__fp_parse_infix_juxtapose:N * \c_thirty_two \c_thirty_two
+ \exp_args:Nc \__fp_tmp:w { __fp_parse_infix_ / :N } / \c_ten \c_ten
+ \exp_args:Nc \__fp_tmp:w { __fp_parse_infix_mul:N } * \c_ten \c_ten
+ \exp_args:Nc \__fp_tmp:w { __fp_parse_infix_ - :N } - \c_nine \c_nine
+ \exp_args:Nc \__fp_tmp:w { __fp_parse_infix_ + :N } + \c_nine \c_nine
+ \exp_args:Nc \__fp_tmp:w { __fp_parse_infix_and:N } & \c_five \c_five
+ \exp_args:Nc \__fp_tmp:w { __fp_parse_infix_ or:N } | \c_four \c_four
+\group_end:
+\group_begin:
+ \char_set_catcode_letter:N ^
+ \__fp_tmp:w \__fp_parse_infix_^:N ^ \c_fifteen \c_fourteen
+ \cs_new:cpn { __fp_parse_infix_*:N } #1#2
+ {
+ \if:w * #2
+ \exp_after:wN \__fp_parse_infix_^:N
+ \exp_after:wN #1
\else:
- \l_fp_output_decimal_int
- \int_eval:w
- \c_one_thousand_million - \l_fp_output_decimal_int
- \scan_stop:
- \l_fp_output_integer_int
- \int_eval:w
- - \l_fp_output_integer_int - \c_one
- \scan_stop:
- \fi:
- \else:
- \l_fp_output_sign_int \l_fp_input_a_sign_int
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_sub:Nn { \fp_sub_aux:NNn \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gsub:Nn { \fp_sub_aux:NNn \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_sub:Nn { c }
-\cs_generate_variant:Nn \fp_gsub:Nn { c }
-\cs_new_protected:Npn \fp_sub_aux:NNn #1#2#3
- {
- \group_begin:
- \fp_read:N #2
- \fp_split:Nn b {#3}
- \fp_standardise:NNNN
- \l_fp_input_b_sign_int
- \l_fp_input_b_integer_int
- \l_fp_input_b_decimal_int
- \l_fp_input_b_exponent_int
- \tex_multiply:D \l_fp_input_b_sign_int \c_minus_one
- \fp_add_core:
- \fp_tmp:w #1#2
- }
-\cs_new_protected_nopar:Npn \fp_mul:Nn { \fp_mul_aux:NNn \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gmul:Nn { \fp_mul_aux:NNn \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_mul:Nn { c }
-\cs_generate_variant:Nn \fp_gmul:Nn { c }
-\cs_new_protected:Npn \fp_mul_aux:NNn #1#2#3
- {
- \group_begin:
- \fp_read:N #2
- \fp_split:Nn b {#3}
- \fp_standardise:NNNN
- \l_fp_input_b_sign_int
- \l_fp_input_b_integer_int
- \l_fp_input_b_decimal_int
- \l_fp_input_b_exponent_int
- \fp_mul_internal:
- \l_fp_output_exponent_int
- \int_eval:w
- \l_fp_input_a_exponent_int + \l_fp_input_b_exponent_int
- \scan_stop:
- \fp_standardise:NNNN
- \l_fp_output_sign_int
- \l_fp_output_integer_int
- \l_fp_output_decimal_int
- \l_fp_output_exponent_int
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2
- {
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_sign_int * \l_fp_input_b_sign_int
- < \c_zero
- \if_int_compare:w
- \int_eval:w
- \l_fp_output_integer_int + \l_fp_output_decimal_int
- = \c_zero
- +
- \else:
- -
- \fi:
- \else:
- +
- \fi:
- \int_use:N \l_fp_output_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_output_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_output_exponent_int
- }
- }
- \fp_tmp:w
- }
-\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
- \l_fp_mul_b_i_int \l_fp_mul_b_ii_int \l_fp_mul_b_iii_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_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
- \tex_divide:D \l_fp_mul_output_int \c_one_thousand
- \fp_mul_product:NN \l_fp_input_a_integer_int \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 \l_fp_input_b_integer_int
- \fp_mul_end_level:
- \fp_mul_product:NN \l_fp_input_a_integer_int \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 \l_fp_input_b_integer_int
- \fp_mul_end_level:
- \fp_mul_product:NN \l_fp_input_a_integer_int \l_fp_mul_b_i_int
- \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_input_b_integer_int
- \fp_mul_end_level:
- \l_fp_output_decimal_int 0 \l_fp_mul_output_tl \scan_stop:
- \tl_clear:N \l_fp_mul_output_tl
- \fp_mul_product:NN \l_fp_input_a_integer_int \l_fp_input_b_integer_int
- \fp_mul_end_level:
- \l_fp_output_integer_int 0 \l_fp_mul_output_tl \scan_stop:
- }
-\cs_new_protected:Npn \fp_mul_split:NNNN #1#2#3#4
- {
- \tex_advance:D #1 \c_one_thousand_million
- \cs_set_protected:Npn \fp_mul_split_aux:w
- ##1##2##3##4##5##6##7##8##9 \q_stop {
- #2 ##2##3##4 \scan_stop:
- #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_advance:D #1 -\c_one_thousand_million
+ \exp_after:wN \__fp_parse_infix_mul:N
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \fi:
+ }
+\group_end:
+\group_begin:
+ \char_set_catcode_letter:N \|
+ \char_set_catcode_letter:N \&
+ \cs_new:Npn \__fp_parse_infix_|:N #1#2
+ {
+ \if:w | #2
+ \exp_after:wN \__fp_parse_infix_|:N
+ \exp_after:wN #1
+ \tex_romannumeral:D \exp_after:wN \__fp_parse_expand:w
+ \else:
+ \exp_after:wN \__fp_parse_infix_or:N
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \fi:
+ }
+ \cs_new:Npn \__fp_parse_infix_&:N #1#2
+ {
+ \if:w & #2
+ \exp_after:wN \__fp_parse_infix_&:N
+ \exp_after:wN #1
+ \tex_romannumeral:D \exp_after:wN \__fp_parse_expand:w
+ \else:
+ \exp_after:wN \__fp_parse_infix_and:N
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \fi:
+ }
+\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 <
}
-\cs_new_protected:Npn \fp_mul_product:NN #1#2
+\cs_new:cpn { __fp_parse_infix_=:N } #1
{
- \l_fp_mul_output_int
- \int_eval:w \l_fp_mul_output_int + #1 * #2 \scan_stop:
+ \__fp_infix_compare:N #1 \c_one_fp
+ \c_zero_fp \c_zero_fp \c_zero_fp \c_zero_fp =
}
-\cs_new_protected_nopar:Npn \fp_mul_end_level:
+\cs_new:cpn { __fp_parse_infix_>:N } #1
{
- \tex_advance:D \l_fp_mul_output_int \c_one_thousand_million
- \exp_after:wN \use_i:nn \exp_after:wN
- \fp_mul_end_level:NNNNNNNNN \int_use:N \l_fp_mul_output_int
+ \__fp_infix_compare:N #1 \c_one_fp
+ \c_zero_fp \c_zero_fp \c_zero_fp \c_zero_fp >
}
-\cs_new_protected:Npn \fp_mul_end_level:NNNNNNNNN #1#2#3#4#5#6#7#8#9
+\cs_new:cpn { __fp_parse_infix_!:N } #1
{
- \tl_set:Nx \l_fp_mul_output_tl { #7#8#9 \l_fp_mul_output_tl }
- \l_fp_mul_output_int #1#2#3#4#5#6 \scan_stop:
+ \exp_after:wN \__fp_parse_infix_excl_aux:NN
+ \exp_after:wN #1 \tex_romannumeral:D \__fp_parse_expand:w
}
-\cs_new_protected_nopar:Npn \fp_div:Nn { \fp_div_aux:NNn \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gdiv:Nn { \fp_div_aux:NNn \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_div:Nn { c }
-\cs_generate_variant:Nn \fp_gdiv:Nn { c }
-\cs_new_protected:Npn \fp_div_aux:NNn #1#2#3
- {
- \group_begin:
- \fp_read:N #2
- \fp_split:Nn b {#3}
- \fp_standardise:NNNN
- \l_fp_input_b_sign_int
- \l_fp_input_b_integer_int
- \l_fp_input_b_decimal_int
- \l_fp_input_b_exponent_int
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int
- = \c_zero
- \cs_set_protected:Npx \fp_tmp:w ##1##2
- {
- \group_end:
- #1 \exp_not:N #2 { \c_undefined_fp }
- }
+\cs_new:Npn \__fp_parse_infix_excl_aux:NN #1#2
+ {
+ \if_catcode:w \tex_relax:D #2
+ \__fp_parse_infix_excl_error:
+ \else:
+ \if_int_compare:w `#2 > `? \exp_stop_f:
+ \__fp_parse_infix_excl_error:
\else:
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int
- = \c_zero
- \cs_set_protected:Npx \fp_tmp:w ##1##2
- {
- \group_end:
- #1 \exp_not:N #2 { \c_zero_fp }
- }
+ \if_int_compare:w `#2 < `< \exp_stop_f:
+ \__fp_parse_infix_excl_error:
+ \fi:
+ \fi:
+ \fi:
+ \__fp_infix_compare:N #1 \c_zero_fp
+ \c_one_fp \c_one_fp \c_one_fp \c_one_fp #2
+ }
+\cs_new:Npn \__fp_parse_infix_excl_error:
+ { \__msg_expandable_error:n { Missing~relation~symbol~after~'!'. } }
+\cs_new:Npn \__fp_infix_compare:N #1
+ {
+ \if_int_compare:w #1 < \c_seven
+ \exp_after:wN \__fp_parse_compare:NNNNNw
+ \else:
+ \exp_after:wN @
+ \exp_after:wN \__fp_parse_stop_until:N
+ \exp_after:wN \__fp_infix_compare:N
+ \fi:
+ }
+\cs_new:Npn \__fp_parse_compare:NNNNNw #1#2#3#4#5#6
+ {
+ \if_case:w
+ \if_catcode:w \tex_relax:D #6
+ \c_minus_one
+ \else:
+ \__int_eval:w `#6 - `< \__int_eval_end:
+ \fi:
+ \__fp_parse_compare_expand:NNNNNw #1#1#3#4#5
+ \or: \__fp_parse_compare_expand:NNNNNw #1#2#1#4#5
+ \or: \__fp_parse_compare_expand:NNNNNw #1#2#3#1#5
+ \or: \__fp_parse_compare_expand:NNNNNw #1#2#3#4#1
+ \else: \__fp_parse_compare_end:NNNN #2#3#4#5#6
+ \fi:
+ }
+\cs_new:Npn \__fp_parse_compare_expand:NNNNNw #1#2#3#4#5
+ {
+ \exp_after:wN \__fp_parse_compare:NNNNNw
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \exp_after:wN #3
+ \exp_after:wN #4
+ \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:
+ {
+ \fi:
+ \exp_after:wN @
+ \exp_after:wN \__fp_parse_apply_compare:NwNNNNwN
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \exp_after:wN #3
+ \exp_after:wN #4
+ \tex_romannumeral:D
+ \__fp_parse_until:Nw \c_seven \__fp_parse_expand:w #5
+ }
+\cs_new:Npn \__fp_parse_apply_compare:NwNNNNwN #1 #2@ #3#4#5#6 #7@ #8
+ {
+ \exp_after:wN \__fp_parse_until_test: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:ww #2 #7 \exp_stop_f:
+ #4
+ \or: #5
+ \or: #6
+ \else: #3
+ \fi:
+ \tex_romannumeral:D -`0 #8 #1
+ }
+\group_begin:
+ \char_set_catcode_letter:N \?
+ \cs_new:Npn \__fp_parse_infix_?:N #1
+ {
+ \if_int_compare:w #1 < \c_three
+ \exp_after:wN @
+ \exp_after:wN \__fp_ternary:NwwN
+ \tex_romannumeral:D
+ \__fp_parse_until:Nw \c_three
+ \exp_after:wN \__fp_parse_expand:w
+ \else:
+ \exp_after:wN @
+ \exp_after:wN \__fp_parse_stop_until:N
+ \exp_after:wN \__fp_parse_infix_?:N
+ \fi:
+ }
+ \cs_new:Npn \__fp_parse_infix_::N #1
+ {
+ \if_int_compare:w #1 < \c_three
+ \__msg_expandable_error:n { Missing~'?'~inserted~for~'?:'. }
+ \exp_after:wN @
+ \exp_after:wN \__fp_ternary_ii:NwwN
+ \tex_romannumeral:D
+ \__fp_parse_until:Nw \c_two
+ \exp_after:wN \__fp_parse_expand:w
+ \else:
+ \exp_after:wN @
+ \exp_after:wN \__fp_parse_stop_until:N
+ \exp_after:wN \__fp_parse_infix_::N
+ \fi:
+ }
+\group_end:
+\group_begin:
+ \char_set_catcode_letter:N \)
+ \cs_new:Npn \__fp_parse_infix_):N #1
+ {
+ \if_int_compare:w #1 < \c_zero
+ \__fp_error:n { Extra~')'~ignored. }
+ \exp_after:wN \__fp_parse_infix:NN
+ \exp_after:wN #1
+ \tex_romannumeral:D \exp_after:wN \__fp_parse_expand:w
+ \else:
+ \exp_after:wN @
+ \exp_after:wN \__fp_parse_stop_until:N
+ \exp_after:wN \__fp_parse_infix_):N
+ \fi:
+ }
+\group_end:
+\cs_new:Npn \__fp_parse_infix_end:N #1
+ { @ \__fp_parse_stop_until:N \__fp_parse_infix_end:N }
+\group_begin:
+ \char_set_catcode_letter:N \,
+ \cs_new:Npn \__fp_parse_infix_,:N #1
+ {
+ \if_int_compare:w #1 > \c_one
+ \exp_after:wN @
+ \exp_after:wN \__fp_parse_stop_until:N
+ \exp_after:wN \__fp_parse_infix_,:N
+ \else:
+ \if_int_compare:w #1 = \c_one
+ \exp_after:wN \__fp_parse_infix_comma:w
+ \tex_romannumeral:D
\else:
- \exp_after:wN \exp_after:wN \exp_after:wN \fp_div_internal:
+ \exp_after:wN \__fp_parse_infix_comma_gobble:w
+ \tex_romannumeral:D
\fi:
+ \__fp_parse_until:Nw \c_one
+ \exp_after:wN \__fp_parse_expand:w
\fi:
- \fp_tmp:w #1#2
- }
-\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:
- \l_fp_div_offset_int \c_one_hundred_million
- \fp_div_loop:
- \l_fp_output_exponent_int
- \int_eval:w
- \l_fp_input_a_exponent_int - \l_fp_input_b_exponent_int
- \scan_stop:
- \fp_standardise:NNNN
- \l_fp_output_sign_int
- \l_fp_output_integer_int
- \l_fp_output_decimal_int
- \l_fp_output_exponent_int
- \cs_set_protected:Npx \fp_tmp:w ##1##2
+ }
+ \cs_new:Npn \__fp_parse_infix_comma:w #1 @
+ { #1 @ \__fp_parse_stop_until:N }
+ \cs_new:Npn \__fp_parse_infix_comma_gobble:w #1 @
{
- \group_end:
- ##1 ##2
- {
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_sign_int * \l_fp_input_b_sign_int
- < \c_zero
- \if_int_compare:w
- \int_eval:w
- \l_fp_output_integer_int + \l_fp_output_decimal_int
- = \c_zero
- +
- \else:
- -
- \fi:
+ \__fp_error:n { Unexpected~comma:~extra~arguments~ignored. }
+ @ \__fp_parse_stop_until:N
+ }
+\group_end:
+%% File: l3fp-logic.dtx Copyright (C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\cs_new_eq:NN \fp_if_exist:NTF \cs_if_exist:NTF
+\cs_new_eq:NN \fp_if_exist:NT \cs_if_exist:NT
+\cs_new_eq:NN \fp_if_exist:NF \cs_if_exist:NF
+\cs_new_eq:NN \fp_if_exist_p:N \cs_if_exist_p:N
+\cs_new_eq:NN \fp_if_exist:cTF \cs_if_exist:cTF
+\cs_new_eq:NN \fp_if_exist:cT \cs_if_exist:cT
+\cs_new_eq:NN \fp_if_exist:cF \cs_if_exist:cF
+\cs_new_eq:NN \fp_if_exist_p:c \cs_if_exist_p:c
+\cs_new:Npn \__fp_compare:ww \s__fp \__fp_chk:w #1#2#3; \s__fp \__fp_chk:w #4#5#6;
+ {
+ \__int_value:w
+ \if_meaning:w 3 #1 \exp_after:wN \__fp_compare_nan:w \fi:
+ \if_meaning:w 3 #4 \exp_after:wN \__fp_compare_nan:w \fi:
+ \if_meaning:w 2 #2 - \fi:
+ \if_meaning:w #2 #5
+ \if_meaning:w #1 #4
+ \if_meaning:w 1 #1
+ \__fp_compare_mantissa:ww #3; #6;
\else:
- +
+ 0
\fi:
- \int_use:N \l_fp_output_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_output_decimal_int + \c_one_thousand_million
- \int_eval_end:
- e
- \int_use:N \l_fp_output_exponent_int
- }
- }
-}
-\cs_new_protected_nopar:Npn \fp_div_loop:
- {
- \l_fp_count_int \c_zero
- \fp_div_divide:
- \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
- \int_use:N \l_fp_input_a_decimal_int \q_stop
- \if_int_compare:w
- \int_eval:w \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int
- > \c_zero
- \if_int_compare:w \l_fp_div_offset_int > \c_zero
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_div_loop:
+ \else:
+ \if_int_compare:w #1 < #4 - \fi: 1
\fi:
- \fi:
+ \else:
+ \if_meaning:w 0 #1
+ \if_meaning:w 0 #4
+ 0
+ \else:
+ 1
+ \fi:
+ \else:
+ 1
+ \fi:
+ \fi:
+ \exp_stop_f:
}
-\cs_new_protected_nopar:Npn \fp_div_divide:
+\cs_new:Npn \__fp_compare_nan:w #1 \exp_stop_f: { \c_two }
+\cs_new:Npn \__fp_compare_mantissa:ww #1#2; #3#4;
{
- \if_int_compare:w \l_fp_input_a_integer_int > \l_fp_input_b_integer_int
- \exp_after:wN \fp_div_divide_aux:
+ \if_int_compare:w #1 = #3 \exp_stop_f:
+ \__fp_compare_mantissa:nnnnnnnn #2 #4
\else:
- \if_int_compare:w \l_fp_input_a_integer_int < \l_fp_input_b_integer_int
- \else:
- \if_int_compare:w
- \l_fp_input_a_decimal_int < \l_fp_input_b_decimal_int
+ \if_int_compare:w #1 < #3 - \fi: 1
+ \fi:
+ }
+\cs_new:Npn \__fp_compare_mantissa:nnnnnnnn #1#2#3#4#5#6#7#8
+ {
+ \if_int_compare:w #1 = #5 \exp_stop_f:
+ \if_int_compare:w #2 = #6 \exp_stop_f:
+ \if_int_compare:w #3 = #7 \exp_stop_f:
+ \if_int_compare:w #4 = #8 \exp_stop_f:
+ 0
+ \else:
+ \if_int_compare:w #4 < #8 - \fi: 1
+ \fi:
\else:
- \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:
+ \if_int_compare:w #3 < #7 - \fi: 1
\fi:
+ \else:
+ \if_int_compare:w #2 < #6 - \fi: 1
\fi:
+ \else:
+ \if_int_compare:w #1 < #5 - \fi: 1
\fi:
}
-\cs_new_protected_nopar:Npn \fp_div_divide_aux:
+\prg_new_conditional:Npnn \fp_compare:nNn #1#2#3 { p , T , F , TF }
{
- \tex_advance:D \l_fp_count_int \c_one
- \tex_advance:D \l_fp_input_a_integer_int -\l_fp_input_b_integer_int
- \tex_advance:D \l_fp_input_a_decimal_int -\l_fp_input_b_decimal_int
- \if_int_compare:w \l_fp_input_a_decimal_int < \c_zero
- \tex_advance:D \l_fp_input_a_integer_int \c_minus_one
- \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
+ \if_int_compare:w
+ \exp_after:wN \__fp_compare_aux:wn
+ \tex_romannumeral:D -`0 \__fp_parse:n {#3} {#1}
+ = \__int_eval:w `#2 - `= \__int_eval_end:
+ \prg_return_true:
+ \else:
+ \prg_return_false:
\fi:
- \fp_div_divide:
}
-\cs_new_protected_nopar:Npn \fp_div_store: { }
-\cs_new_protected_nopar:Npn \fp_div_store_integer:
+\cs_new:Npn \__fp_compare_aux:wn #1; #2
{
- \l_fp_output_integer_int \l_fp_count_int
- \cs_set_eq:NN \fp_div_store: \fp_div_store_decimal:
+ \exp_after:wN \__fp_compare:ww
+ \tex_romannumeral:D -`0 \__fp_parse:n {#2} #1;
}
-\cs_new_protected_nopar:Npn \fp_div_store_decimal:
+\prg_new_conditional:Npnn \fp_compare:n #1 { p , T , F , TF }
{
- \l_fp_output_decimal_int
- \int_eval:w
- \l_fp_output_decimal_int +
- \l_fp_count_int * \l_fp_div_offset_int
- \int_eval_end:
- \tex_divide:D \l_fp_div_offset_int \c_ten
+ \exp_after:wN \__fp_compare_aux:w
+ \tex_romannumeral:D -`0 \__fp_parse:n {#1}
}
-\cs_new_protected:Npn \fp_div_loop_step:w #1#2#3#4#5#6#7#8#9 \q_stop
+\cs_new:Npn \__fp_compare_aux:w \s__fp \__fp_chk:w #1#2;
{
- \l_fp_input_a_integer_int
- \int_eval:w #2 + \l_fp_input_a_integer_int \int_eval_end:
- \l_fp_input_a_decimal_int #3#4#5#6#7#8#9 0 \scan_stop:
+ \if_meaning:w 0 #1
+ \prg_return_false:
+ \else:
+ \prg_return_true:
+ \fi:
}
-\cs_new_protected:Npn \fp_add:NNNNNNNNN #1#2#3#4#5#6#7#8#9
+\cs_new:Npn \__fp_not:w \s__fp \__fp_chk:w #1#2;
{
- #7 \int_eval:w #1 + #4 \int_eval_end:
- #8 \int_eval:w #2 + #5 \int_eval_end:
- #9 \int_eval:w #3 + #6 \int_eval_end:
- \if_int_compare:w #9 < \c_one_thousand_million
+ \if_meaning:w 0 #1
+ \exp_after:wN \exp_after:wN \exp_after:wN \c_one_fp
\else:
- \tex_advance:D #8 \c_one
- \tex_advance:D #9 -\c_one_thousand_million
+ \exp_after:wN \exp_after:wN \exp_after:wN \c_zero_fp
\fi:
- \if_int_compare:w #8 < \c_one_thousand_million
+ }
+\cs_new:cpn { __fp_ \iow_char:N \& _o:ww } #1 \s__fp \__fp_chk:w #2#3;
+ {
+ \if_meaning:w 0 #2 #1
+ \__fp_and_return:wNw \s__fp \__fp_chk:w #2#3;
+ \fi:
+ \__fp_exp_after_o:w
+ }
+\cs_new_nopar:cpx { __fp_ \iow_char:N \| _o:ww }
+ { \exp_not:c { __fp_ \iow_char:N \& _o:ww } \exp_not:N \else: }
+\cs_new:Npn \__fp_and_return:wNw #1; \fi: #2#3; { \fi: #2 #1; }
+\cs_new:Npn \__fp_ternary:NwwN #1 #2@ #3@ #4
+ {
+ \if_meaning:w \__fp_parse_infix_::N #4
+ \__fp_ternary_loop:Nw
+ #2
+ \s__fp \__fp_chk:w { \__fp_ternary_loop_break:w } ;
+ \__fp_ternary_break_point:n { \exp_after:wN \__fp_ternary_i:NwwN }
+ \exp_after:wN #1
+ \tex_romannumeral:D -`0
+ \__fp_parse_exp_after_array:wf #3 \s__fp_stop
+ \exp_after:wN @
+ \tex_romannumeral:D
+ \__fp_parse_until:Nw \c_two
+ \__fp_parse_expand:w
\else:
- \tex_advance:D #7 \c_one
- \tex_advance:D #8 -\c_one_thousand_million
+ \__fp_error:n { Missing~':'~clause~for~'?:'. }
+ \exp_after:wN \__fp_parse_until_test:NwN
+ \exp_after:wN #1
+ \tex_romannumeral:D -`0
+ \__fp_parse_exp_after_array:wf #3 \s__fp_stop
+ \exp_after:wN #4
+ \exp_after:wN #1
\fi:
}
-\cs_new_protected:Npn \fp_sub:NNNNNNNNN #1#2#3#4#5#6#7#8#9
+\cs_new:Npn \__fp_ternary_loop_break:w #1 \fi: #2 \__fp_ternary_break_point:n #3
{
- #7 \int_eval:w #1 - #4 \int_eval_end:
- #8 \int_eval:w #2 - #5 \int_eval_end:
- #9 \int_eval:w #3 - #6 \int_eval_end:
- \if_int_compare:w #9 < \c_zero
- \tex_advance:D #8 \c_minus_one
- \tex_advance:D #9 \c_one_thousand_million
- \fi:
- \if_int_compare:w #8 < \c_zero
- \tex_advance:D #7 \c_minus_one
- \tex_advance:D #8 \c_one_thousand_million
+ \c_zero = \c_zero \fi:
+ \exp_after:wN \__fp_ternary_ii:NwwN
+ }
+\cs_new:Npn \__fp_ternary_loop:Nw \s__fp \__fp_chk:w #1#2;
+ {
+ \if_int_compare:w #1 > \c_zero
+ \exp_after:wN \__fp_ternary_map_break:
\fi:
- \if_int_compare:w #7 < \c_zero
- \if_int_compare:w \int_eval:w #8 + #9 = \c_zero
- #7 -#7
- \else:
- \tex_advance:D #7 \c_one
- #8 \int_eval:w \c_one_thousand_million - #8 \int_eval_end:
- #9 \int_eval:w \c_one_thousand_million - #9 \int_eval_end:
- \fi:
- \fi:
- }
-\cs_new_protected:Npn \fp_mul:NNNNNN #1#2#3#4#5#6
- {
- \fp_mul_split:NNNN #1
- \l_fp_mul_a_i_int \l_fp_mul_a_ii_int \l_fp_mul_a_iii_int
- \fp_mul_split:NNNN #2
- \l_fp_mul_a_iv_int \l_fp_mul_a_v_int \l_fp_mul_a_vi_int
- \fp_mul_split:NNNN #3
- \l_fp_mul_b_i_int \l_fp_mul_b_ii_int \l_fp_mul_b_iii_int
- \fp_mul_split:NNNN #4
- \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 \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_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
- \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_end_level:
- \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_end_level:
- #6 0 \l_fp_mul_output_tl \scan_stop:
- \tl_clear:N \l_fp_mul_output_tl
- \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_end_level:
- \fp_mul_product:NN \l_fp_mul_a_i_int \l_fp_mul_b_i_int
- \fp_mul_end_level:
- \fp_mul_end_level:
- #5 0 \l_fp_mul_output_tl \scan_stop:
- }
-\cs_new_protected: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:Npn \fp_div_integer:NNNNN #1#2#3#4#5
- {
- \l_fp_internal_int #1
- \tex_divide:D \l_fp_internal_int #3
- \l_fp_internal_int \int_eval:w #1 - \l_fp_internal_int * #3 \int_eval_end:
+ \__fp_ternary_loop:Nw
+ }
+\cs_new:Npn \__fp_ternary_map_break: #1 \__fp_ternary_break_point:n #2 {#2}
+\cs_new:Npn \__fp_ternary_i:NwwN #1#2@#3@#4
+ {
+ \exp_after:wN \__fp_parse_until_test:NwN
+ \exp_after:wN #1
+ \tex_romannumeral:D -`0
+ \__fp_parse_exp_after_array:wf #2 \s__fp_stop
#4 #1
- \tex_divide:D #4 #3
- #5 #2
- \tex_divide:D #5 #3
- \tex_multiply:D \l_fp_internal_int \c_one_thousand
- \tex_divide:D \l_fp_internal_int #3
- #5 \int_eval:w #5 + \l_fp_internal_int * \c_one_million \int_eval_end:
- \if_int_compare:w #5 > \c_one_thousand_million
- \tex_advance:D #4 \c_one
- \tex_advance:D #5 -\c_one_thousand_million
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_extended_normalise:
- {
- \fp_extended_normalise_aux_i:
- \fp_extended_normalise_aux_ii:
- }
-\cs_new_protected_nopar:Npn \fp_extended_normalise_aux_i:
- {
- \if_int_compare:w \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_extended_normalise_aux_i:w
- \int_use:N \l_fp_input_a_decimal_int \q_stop
- \exp_after:wN \fp_extended_normalise_aux_i:
- \fi:
- }
-\cs_new_protected:Npn \fp_extended_normalise_aux_i:w
- #1#2#3#4#5#6#7#8#9 \q_stop
- {
- \l_fp_input_a_integer_int
- \int_eval:w \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
- \exp_after:wN \fp_extended_normalise_aux_ii:w
- \int_use:N \l_fp_input_a_extended_int \q_stop
- }
-\cs_new_protected:Npn \fp_extended_normalise_aux_ii:w
- #1#2#3#4#5#6#7#8#9 \q_stop
- {
- \l_fp_input_a_decimal_int
- \int_eval:w \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_extended_normalise_aux_ii:
- {
- \if_int_compare:w \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_extended_normalise_ii_aux:NNNNNNNNN
- \int_use:N \l_fp_input_a_decimal_int
- \exp_after:wN \fp_extended_normalise_aux_ii:
- \fi:
- }
-\cs_new_protected:Npn \fp_extended_normalise_ii_aux:NNNNNNNNN
- #1#2#3#4#5#6#7#8#9
- {
- \if_int_compare:w \l_fp_input_a_integer_int = \c_zero
- \l_fp_input_a_decimal_int #1#2#3#4#5#6#7#8 \scan_stop:
- \else:
- \tl_set:Nx \l_fp_internal_tl
- {
- \int_use:N \l_fp_input_a_integer_int
- #1#2#3#4#5#6#7#8
- }
- \l_fp_input_a_integer_int \c_zero
- \l_fp_input_a_decimal_int \l_fp_internal_tl \scan_stop:
- \fi:
- \tex_divide:D \l_fp_input_a_extended_int \c_ten
- \tl_set:Nx \l_fp_internal_tl
- {
- #9
- \int_use:N \l_fp_input_a_extended_int
- }
- \l_fp_input_a_extended_int \l_fp_internal_tl \scan_stop:
- \tex_advance:D \l_fp_input_a_exponent_int \c_one
}
-\cs_new_protected_nopar:Npn \fp_extended_normalise_output:
+\cs_new:Npn \__fp_ternary_ii:NwwN #1#2@#3@#4
{
- \if_int_compare:w \l_fp_output_integer_int > \c_nine
- \tex_advance:D \l_fp_output_integer_int \c_one_thousand_million
- \exp_after:wN \use_i:nn \exp_after:wN
- \fp_extended_normalise_output_aux_i:NNNNNNNNN
- \int_use:N \l_fp_output_integer_int
- \exp_after:wN \fp_extended_normalise_output:
- \fi:
+ \exp_after:wN \__fp_parse_until_test:NwN
+ \exp_after:wN #1
+ \tex_romannumeral:D -`0
+ \__fp_parse_exp_after_array:wf #3 \s__fp_stop
+ #4 #1
}
-\cs_new_protected:Npn \fp_extended_normalise_output_aux_i:NNNNNNNNN
- #1#2#3#4#5#6#7#8#9
+\cs_new:Npn \__fp_max:w #1@
{
- \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_internal_tl
- {
- #9
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_output_decimal_int
- }
- \exp_after:wN \fp_extended_normalise_output_aux_ii:NNNNNNNNN
- \l_fp_internal_tl
+ \exp_after:wN \__fp_minmax_loop:Nww
+ \exp_after:wN \c_minus_one
+ \c_minus_inf_fp
+ #1
+ \s__fp \__fp_chk:w { 3 \__fp_minmax_break:w } ;
}
-\cs_new_protected:Npn \fp_extended_normalise_output_aux_ii:NNNNNNNNN
- #1#2#3#4#5#6#7#8#9
+\cs_new:Npn \__fp_min:w #1@
{
- \l_fp_output_decimal_int #1#2#3#4#5#6#7#8#9 \scan_stop:
- \fp_extended_normalise_output_aux:N
+ \exp_after:wN \__fp_minmax_loop:Nww
+ \exp_after:wN \c_one
+ \c_inf_fp
+ #1
+ \s__fp \__fp_chk:w { 3 \__fp_minmax_break:w } ;
}
-\cs_new_protected:Npn \fp_extended_normalise_output_aux:N #1
+\cs_new:Npn \__fp_minmax_loop:Nww
+ #1 \s__fp \__fp_chk:w #2#3; \s__fp \__fp_chk:w #4#5;
{
- \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_internal_tl
- {
- #1
- \exp_after:wN \use_none:n
- \int_use:N \l_fp_output_extended_int
- }
- \l_fp_output_extended_int \l_fp_internal_tl \scan_stop:
- \tex_advance:D \l_fp_output_exponent_int \c_one
- }
-\cs_new_protected_nopar:Npn \fp_trig_normalise:
- {
- \if_int_compare:w \l_fp_input_a_exponent_int < \c_ten
- \l_fp_input_a_extended_int \c_zero
- \fp_extended_normalise:
- \fp_trig_normalise_aux:
- \if_int_compare:w \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
- \fi:
- \exp_after:wN \fp_trig_octant:
- \else:
- \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:
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_trig_normalise_aux:
- {
- \if_int_compare:w \l_fp_input_a_integer_int > \c_three
- \fp_trig_sub:NNN
- \c_six \c_fp_two_pi_decimal_int \c_fp_two_pi_extended_int
- \exp_after:wN \fp_trig_normalise_aux:
- \else:
- \if_int_compare:w \l_fp_input_a_integer_int > \c_two
- \if_int_compare:w \l_fp_input_a_decimal_int > \c_fp_pi_decimal_int
- \fp_trig_sub:NNN
- \c_six \c_fp_two_pi_decimal_int \c_fp_two_pi_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:
- \fi:
+ \if_meaning:w 3 #4
+ \if_meaning:w 3 #2
+ \__fp_minmax_i:ww
+ \else:
+ \__fp_minmax_ii:ww
+ \fi:
+ \else:
+ \if_int_compare:w \__fp_compare:ww \s__fp \__fp_chk:w #2#3;
+ \s__fp \__fp_chk:w #4#5; = #1
+ \__fp_minmax_ii:ww
+ \else:
+ \__fp_minmax_i:ww
\fi:
\fi:
- }
-\cs_new_protected:Npn \fp_trig_sub:NNN #1#2#3
+ \__fp_minmax_loop:Nww #1
+ \s__fp \__fp_chk:w #2#3;
+ \s__fp \__fp_chk:w #4#5;
+ }
+\cs_new:Npn \__fp_minmax_i:ww
+ #1 \__fp_minmax_loop:Nww #2 \s__fp #3; \s__fp #4;
+ { #1 \__fp_minmax_loop:Nww #2 \s__fp #3; }
+\cs_new:Npn \__fp_minmax_ii:ww
+ #1 \__fp_minmax_loop:Nww #2 \s__fp #3; \s__fp #4;
+ { #1 \__fp_minmax_loop:Nww #2 \s__fp #4; }
+\cs_new:Npn \__fp_minmax_break:w #1 \__fp_minmax_loop:Nww #2 #3; #4;
{
- \l_fp_input_a_integer_int
- \int_eval:w \l_fp_input_a_integer_int - #1 \int_eval_end:
- \l_fp_input_a_decimal_int
- \int_eval:w \l_fp_input_a_decimal_int - #2 \int_eval_end:
- \l_fp_input_a_extended_int
- \int_eval:w \l_fp_input_a_extended_int - #3 \int_eval_end:
- \if_int_compare:w \l_fp_input_a_extended_int < \c_zero
- \tex_advance:D \l_fp_input_a_decimal_int \c_minus_one
- \tex_advance:D \l_fp_input_a_extended_int \c_one_thousand_million
\fi:
- \if_int_compare:w \l_fp_input_a_decimal_int < \c_zero
- \tex_advance:D \l_fp_input_a_integer_int \c_minus_one
- \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
+ \__fp_exp_after_o:w #3;
+ }
+%% File: l3fp-basics.dtx Copyright (C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\cs_new:Npn \__fp_basics_pack_low:NNNNNw #1 #2#3#4#5 #6;
+ {
+ \if_meaning:w 2 #1
+ + \c_one
\fi:
- \if_int_compare:w \l_fp_input_a_integer_int < \c_zero
- \l_fp_input_a_sign_int -\l_fp_input_a_sign_int
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int
- = \c_zero
- \l_fp_input_a_integer_int -\l_fp_input_a_integer_int
- \else:
- \l_fp_input_a_integer_int
- \int_eval:w
- - \l_fp_input_a_integer_int - \c_one
- \int_eval_end:
- \l_fp_input_a_decimal_int
- \int_eval:w
- \c_one_thousand_million - \l_fp_input_a_decimal_int
- \int_eval_end:
- \l_fp_input_a_extended_int
- \int_eval:w
- \c_one_thousand_million - \l_fp_input_a_extended_int
- \int_eval_end:
- \fi:
+ ; {#2#3#4#5} {#6} ;
+ }
+\cs_new:Npn \__fp_basics_pack_high:NNNNNw #1 #2#3#4#5 #6;
+ {
+ \if_meaning:w 2 #1
+ \__fp_basics_pack_high_carry:w
\fi:
+ ; {#2#3#4#5} {#6}
}
-\cs_new_protected_nopar:Npn \fp_trig_octant:
+\cs_new:Npn \__fp_basics_pack_high_carry:w \fi: ; #1
+ { \fi: + \c_one ; {1000} }
+\cs_new:Npn \__fp_basics_return_nan_nan:NNww #1#2 #3; #4;
+ { \__fp_exp_after_o:w \s__fp \__fp_chk:w 3 1 #3 ; }
+\cs_new:Npn \__fp_basics_return_zero:NNww #1#2 #3; #4;
{
- \l_fp_trig_octant_int \c_one
- \fp_trig_octant_aux_i:
- \if_int_compare:w \l_fp_input_a_decimal_int < \c_ten
- \l_fp_input_a_decimal_int \c_zero
- \l_fp_input_a_extended_int \c_zero
+ \if_meaning:w #1 #2
+ \exp_after:wN \exp_after:wN \exp_after:wN \c_zero_fp
+ \else:
+ \exp_after:wN \exp_after:wN \exp_after:wN \c_minus_zero_fp
\fi:
- \if_int_odd:w \l_fp_trig_octant_int
+ }
+\cs_new:Npn \__fp_basics_return_inf:NNww #1#2 #3; #4;
+ {
+ \if_meaning:w #1 #2
+ \exp_after:wN \exp_after:wN \exp_after:wN \c_inf_fp
\else:
- \fp_sub:NNNNNNNNN
- \c_zero \c_fp_pi_by_four_decimal_int \c_fp_pi_by_four_extended_int
- \l_fp_input_a_integer_int \l_fp_input_a_decimal_int
- \l_fp_input_a_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 \c_minus_inf_fp
\fi:
}
-\cs_new_protected_nopar:Npn \fp_trig_octant_aux_i:
+\cs_new:Npn \__fp_basics_return_i:NNNNww #1#2 #3#4 #5; #6;
+ { \__fp_exp_after_o:w \s__fp \__fp_chk:w #1 #3 #5; }
+\cs_new:Npn \__fp_basics_return_ii:NNNNww #1#2 #3#4 #5; #6;
+ { \__fp_exp_after_o:w \s__fp \__fp_chk:w #2 #4 #6; }
+\cs_new:Npn \__fp_basics_return_nan:NNww #1#2
{
- \if_int_compare:w \l_fp_trig_octant_int > \c_four
- \l_fp_trig_octant_int \c_four
- \l_fp_input_a_decimal_int \c_fp_pi_by_four_decimal_int
- \l_fp_input_a_extended_int \c_fp_pi_by_four_extended_int
+ \if_meaning:w 1 #1
+ \exp_after:wN \__fp_basics_return_i:NNNNww
\else:
- \exp_after:wN \fp_trig_octant_aux_ii:
+ \exp_after:wN \__fp_basics_return_ii:NNNNww
\fi:
+ 3 3 #1 #2
}
-\cs_new_protected_nopar:Npn \fp_trig_octant_aux_ii:
+\cs_new:cpn { __fp_+_o:ww }
+ \s__fp \__fp_chk:w #1 #2 #3 ; \s__fp \__fp_chk:w #4 #5
+ { \__fp_add_cases:NN #1 #4 #2 #5 #3 ; }
+\cs_new:cpn { __fp_-_o:ww }
+ \s__fp \__fp_chk:w #1 #2 #3 ; \s__fp \__fp_chk:w #4 #5
{
- \if_int_compare:w \l_fp_input_a_integer_int > \c_zero
- \fp_sub:NNNNNNNNN
- \l_fp_input_a_integer_int \l_fp_input_a_decimal_int
- \l_fp_input_a_extended_int
- \c_zero \c_fp_pi_by_four_decimal_int \c_fp_pi_by_four_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_trig_octant_int \c_one
- \exp_after:wN \fp_trig_octant_aux_i:
+ \exp_after:wN \__fp_add_cases:NN
+ \exp_after:wN #1
+ \exp_after:wN #4
+ \exp_after:wN #2
+ \int_use:N \__int_eval:w \c_two - #5 \__int_eval_end:
+ #3 ;
+ }
+\cs_new:Npn \__fp_add_cases:NN #1 #2
+ {
+ \if_int_compare:w #1 = #2 \exp_stop_f:
+ \exp_after:wN \__fp_add_cases_eq:N
\else:
- \if_int_compare:w
- \l_fp_input_a_decimal_int > \c_fp_pi_by_four_decimal_int
- \fp_sub:NNNNNNNNN
- \l_fp_input_a_integer_int \l_fp_input_a_decimal_int
- \l_fp_input_a_extended_int
- \c_zero \c_fp_pi_by_four_decimal_int
- \c_fp_pi_by_four_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_trig_octant_int \c_one
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_trig_octant_aux_i:
- \fi:
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_sin:Nn { \fp_sin_aux:NNn \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gsin:Nn { \fp_sin_aux:NNn \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_sin:Nn { c }
-\cs_generate_variant:Nn \fp_gsin:Nn { c }
-\cs_new_protected:Npn \fp_sin_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
- \tl_set:Nx \l_fp_arg_tl
- {
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- -
- \else:
- +
- \fi:
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_input_a_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_input_a_exponent_int
- }
- \if_int_compare:w \l_fp_input_a_exponent_int < -\c_five
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2 { \l_fp_arg_tl }
- }
+ \if_int_compare:w #1 < #2 \exp_stop_f:
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_basics_return_ii:NNNNww
\else:
- \if_cs_exist:w
- c_fp_sin ( \l_fp_arg_tl ) _fp
- \cs_end:
- \else:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_sin_aux_i:
- \fi:
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2
- { \use:c { c_fp_sin ( \l_fp_arg_tl ) _fp } }
- }
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_basics_return_i:NNNNww
\fi:
- \fp_tmp:w
+ \exp_after:wN #1
+ \fi:
+ #2
}
-\cs_new_protected_nopar:Npn \fp_sin_aux_i:
+\cs_new:Npn \__fp_add_cases_eq:N #1
{
- \fp_trig_normalise:
- \fp_sin_aux_ii:
- \if_int_compare:w \l_fp_output_integer_int = \c_one
- \l_fp_output_exponent_int \c_zero
+ \if_case:w #1 \exp_stop_f:
+ \exp_after:wN \__fp_add_zeros:NNww
+ \or: \exp_after:wN \__fp_add_normal:NNww
+ \or: \exp_after:wN \__fp_add_inf:NNww
+ \or: \exp_after:wN \__fp_basics_return_nan_nan:NNww
+ \fi:
+ }
+\cs_new:Npn \__fp_add_zeros:NNww #1#2 #3;
+ {
+ \if_int_compare:w #1 #2 = 02 \exp_stop_f:
+ \__fp_case_return_o:Nw \c_zero_fp
\else:
- \l_fp_output_integer_int \l_fp_output_decimal_int
- \l_fp_output_decimal_int \l_fp_output_extended_int
- \l_fp_output_exponent_int -\c_nine
+ \__fp_case_return_same_o:w
\fi:
- \fp_standardise:NNNN
- \l_fp_input_a_sign_int
- \l_fp_output_integer_int
- \l_fp_output_decimal_int
- \l_fp_output_exponent_int
- \tl_new:c { c_fp_sin ( \l_fp_arg_tl ) _fp }
- \tl_gset:cx { c_fp_sin ( \l_fp_arg_tl ) _fp }
- {
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- +
- \else:
- -
- \fi:
- \int_use:N \l_fp_output_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_output_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_output_exponent_int
- }
+ \s__fp \__fp_chk:w 0 #2
}
-\cs_new_protected_nopar:Npn \fp_sin_aux_ii:
+\cs_new:Npn \__fp_add_inf:NNww #1#2 #3;
{
- \if_case:w \l_fp_trig_octant_int
- \or:
- \exp_after:wN \fp_trig_calc_sin:
- \or:
- \exp_after:wN \fp_trig_calc_cos:
- \or:
- \exp_after:wN \fp_trig_calc_cos:
- \or:
- \exp_after:wN \fp_trig_calc_sin:
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_cos:Nn { \fp_cos_aux:NNn \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gcos:Nn { \fp_cos_aux:NNn \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_cos:Nn { c }
-\cs_generate_variant:Nn \fp_gcos:Nn { c }
-\cs_new_protected:Npn \fp_cos_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
- \tl_set:Nx \l_fp_arg_tl
+ \if_meaning:w #1 #2
+ \__fp_case_return_same_o:w
+ \else:
+ \__fp_case_use:nw
{
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- -
- \else:
- +
- \fi:
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_input_a_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_input_a_exponent_int
+ \__fp_invalid_operation:Nnww \c_nan_fp { + }
+ \s__fp \__fp_chk:w 2 #1 #3 ;
}
- \if_cs_exist:w c_fp_cos ( \l_fp_arg_tl ) _fp \cs_end:
+ \fi:
+ \s__fp \__fp_chk:w 2 #2
+ }
+\cs_new:Npn \__fp_add_normal:NNww #1#2
+ {
+ \if_meaning:w #1#2
+ \exp_after:wN \__fp_add_npos:Nnwnw
+ \else:
+ \exp_after:wN \__fp_sub_npos:Nnwnw
+ \fi:
+ #1
+ }
+\cs_new:Npn \__fp_add_npos:Nnwnw #1 #2#3; #4
+ {
+ \exp_after:wN \__fp_sanitize:Nw
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w
+ \if_int_compare:w #2 > #4 \exp_stop_f:
+ #2
+ \exp_after:wN \__fp_add_big_i:wNww \__int_value:w -
\else:
- \exp_after:wN \fp_cos_aux_i:
+ #4
+ \exp_after:wN \__fp_add_big_ii:wNww \__int_value:w
\fi:
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2
- { \use:c { c_fp_cos ( \l_fp_arg_tl ) _fp } }
- }
- \fp_tmp:w
- }
-\cs_new_protected_nopar:Npn \fp_cos_aux_i:
- {
- \fp_trig_normalise:
- \fp_cos_aux_ii:
- \if_int_compare:w \l_fp_output_integer_int = \c_one
- \l_fp_output_exponent_int \c_zero
- \else:
- \l_fp_output_integer_int \l_fp_output_decimal_int
- \l_fp_output_decimal_int \l_fp_output_extended_int
- \l_fp_output_exponent_int -\c_nine
- \fi:
- \fp_standardise:NNNN
- \l_fp_input_a_sign_int
- \l_fp_output_integer_int
- \l_fp_output_decimal_int
- \l_fp_output_exponent_int
- \tl_new:c { c_fp_cos ( \l_fp_arg_tl ) _fp }
- \tl_gset:cx { c_fp_cos ( \l_fp_arg_tl ) _fp }
- {
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- +
- \else:
- -
- \fi:
- \int_use:N \l_fp_output_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_output_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_output_exponent_int
- }
+ \__int_eval:w #4 - #2 ; #1 #3;
}
-\cs_new_protected_nopar:Npn \fp_cos_aux_ii:
+\cs_new:Npn \__fp_add_big_i:wNww #1; #2 #3; #4;
{
- \if_case:w \l_fp_trig_octant_int
- \or:
- \exp_after:wN \fp_trig_calc_cos:
- \or:
- \exp_after:wN \fp_trig_calc_sin:
- \or:
- \exp_after:wN \fp_trig_calc_sin:
- \or:
- \exp_after:wN \fp_trig_calc_cos:
+ \__fp_decimate:nNnnnn {#1}
+ \__fp_add_mantissa:NnnwnnnnN
+ #4
+ #3
+ #2
+ }
+\cs_new:Npn \__fp_add_big_ii:wNww #1; #2 #3; #4;
+ {
+ \__fp_decimate:nNnnnn {#1}
+ \__fp_add_mantissa:NnnwnnnnN
+ #3
+ #4
+ #2
+ }
+\cs_new:Npn \__fp_add_mantissa:NnnwnnnnN #1 #2#3 #4; #5#6#7#8
+ {
+ \exp_after:wN \__fp_add_mantissa_test:N
+ \int_use:N \__int_eval:w 1#5#6 + #2
+ \exp_after:wN \__fp_add_mantissa_pack:NNNNNNN
+ \int_use:N \__int_eval:w 1#7#8 + #3 ; #1
+ }
+\cs_new:Npn \__fp_add_mantissa_pack:NNNNNNN #1 #2#3#4#5#6#7
+ {
+ \if:w 2 #1
+ + \c_one
\fi:
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- \if_int_compare:w \l_fp_trig_octant_int > \c_two
- \l_fp_input_a_sign_int \c_minus_one
- \fi:
+ ; #2 #3 #4 #5 #6 #7 ;
+ }
+\cs_new:Npn \__fp_add_mantissa_test:N #1
+ {
+ \if:w 2 #1
+ \exp_after:wN \__fp_add_mantissa_carry:wwNNNN
\else:
- \if_int_compare:w \l_fp_trig_octant_int > \c_two
- \else:
- \l_fp_input_a_sign_int \c_one
- \fi:
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_trig_calc_cos:
- {
- \if_int_compare:w \l_fp_input_a_decimal_int = \c_zero
- \l_fp_output_integer_int \c_one
- \l_fp_output_decimal_int \c_zero
- \else:
- \l_fp_trig_sign_int \c_minus_one
- \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_trig_decimal_int \l_fp_trig_extended_int
- \fp_div_integer:NNNNN
- \l_fp_trig_decimal_int \l_fp_trig_extended_int
- \c_two
- \l_fp_trig_decimal_int \l_fp_trig_extended_int
- \l_fp_count_int \c_three
- \if_int_compare:w \l_fp_trig_extended_int = \c_zero
- \if_int_compare:w \l_fp_trig_decimal_int = \c_zero
- \l_fp_output_integer_int \c_one
- \l_fp_output_decimal_int \c_zero
- \l_fp_output_extended_int \c_zero
- \else:
- \l_fp_output_integer_int \c_zero
- \l_fp_output_decimal_int \c_one_thousand_million
- \l_fp_output_extended_int \c_zero
- \fi:
+ \exp_after:wN \__fp_add_mantissa_no_carry:wwNNNN
+ \fi:
+ }
+\cs_new:Npn \__fp_add_mantissa_no_carry:wwNNNN
+ #1; #2; #3#4 ; #5#6
+ {
+ \exp_after:wN \__fp_basics_pack_high:NNNNNw
+ \int_use:N \__int_eval:w 1 #1
+ \exp_after:wN \__fp_basics_pack_low:NNNNNw
+ \int_use:N \__int_eval:w 1 #2 #3#4
+ + \__fp_round:NNN #6 #4 #5
+ \exp_after:wN ;
+ }
+\cs_new:Npn \__fp_add_mantissa_carry:wwNNNN
+ #1; #2; #3#4; #5#6
+ {
+ + \c_one
+ \exp_after:wN \__fp_add_mantissa_carry_pack:NNNNNNNNw
+ \int_use:N \__int_eval:w 1 #1
+ \exp_after:wN \__fp_add_mantissa_carry_pack_ii:NNNNw
+ \int_use:N \__int_eval:w 1 #2#3
+ + \__fp_round:NNNN #6 #3 #4 #5
+ \exp_after:wN ;
+ }
+\cs_new:Npn \__fp_add_mantissa_carry_pack_ii:NNNNw #1 #2#3#4 #5;
+ {
+ \if:w 2 #1
+ + \c_one
+ \fi:
+ \__int_eval_end:
+ #2#3#4; {#5} ;
+ }
+\cs_new:Npn \__fp_add_mantissa_carry_pack:NNNNNNNNw
+ #1#2#3#4 #5#6#7#8 #9; { ; {#1#2#3#4} {#5#6#7#8} {#9} }
+\cs_new:Npn \__fp_sub_npos:Nnwnw #1 #2#3; #4 #5;
+ {
+ \exp_after:wN \__fp_sanitize:wN
+ \int_use:N \__int_eval:w
+ \if_int_compare:w #2 > #4 \exp_stop_f:
+ #2
+ \exp_after:wN \__fp_sub_big_i:wNww \__int_value:w -
\else:
- \l_fp_output_integer_int \c_zero
- \l_fp_output_decimal_int 999999999 \scan_stop:
- \l_fp_output_extended_int \c_one_thousand_million
- \fi:
- \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_Taylor:
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_trig_calc_sin:
- {
- \l_fp_output_integer_int \c_zero
- \if_int_compare:w \l_fp_input_a_decimal_int = \c_zero
- \l_fp_output_decimal_int \c_zero
- \else:
- \l_fp_output_decimal_int \l_fp_input_a_decimal_int
- \l_fp_output_extended_int \l_fp_input_a_extended_int
- \l_fp_trig_sign_int \c_one
- \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_Taylor:
- \fi:
- }
-\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
- \l_fp_input_a_decimal_int \l_fp_input_a_extended_int
- \l_fp_trig_decimal_int \l_fp_trig_extended_int
- \fp_mul:NNNNNN
- \l_fp_trig_decimal_int \l_fp_trig_extended_int
- \l_fp_input_a_decimal_int \l_fp_input_a_extended_int
- \l_fp_trig_decimal_int \l_fp_trig_extended_int
- \fp_div_integer:NNNNN
- \l_fp_trig_decimal_int \l_fp_trig_extended_int
- \l_fp_count_int
- \l_fp_trig_decimal_int \l_fp_trig_extended_int
- \tex_advance:D \l_fp_count_int \c_one
- \fp_div_integer:NNNNN
- \l_fp_trig_decimal_int \l_fp_trig_extended_int
- \l_fp_count_int
- \l_fp_trig_decimal_int \l_fp_trig_extended_int
- \tex_advance:D \l_fp_count_int \c_one
- \if_int_compare:w \l_fp_trig_decimal_int > \c_zero
- \if_int_compare:w \l_fp_trig_sign_int > \c_zero
- \tex_advance:D \l_fp_output_decimal_int \l_fp_trig_decimal_int
- \tex_advance:D \l_fp_output_extended_int
- \l_fp_trig_extended_int
- \if_int_compare:w \l_fp_output_extended_int < \c_one_thousand_million
- \else:
- \tex_advance:D \l_fp_output_decimal_int \c_one
- \tex_advance:D \l_fp_output_extended_int
- -\c_one_thousand_million
- \fi:
- \if_int_compare:w \l_fp_output_decimal_int < \c_one_thousand_million
+ #4
+ \if_int_compare:w #2 = #4 \exp_stop_f:
+ \__fp_sub_exponent_eq:nnnnnnnn #3 #5
\else:
- \tex_advance:D \l_fp_output_integer_int \c_one
- \tex_advance:D \l_fp_output_decimal_int
- -\c_one_thousand_million
- \fi:
- \else:
- \tex_advance:D \l_fp_output_decimal_int -\l_fp_trig_decimal_int
- \tex_advance:D \l_fp_output_extended_int
- -\l_fp_input_a_extended_int
- \if_int_compare:w \l_fp_output_extended_int < \c_zero
- \tex_advance:D \l_fp_output_decimal_int \c_minus_one
- \tex_advance:D \l_fp_output_extended_int \c_one_thousand_million
- \fi:
- \if_int_compare:w \l_fp_output_decimal_int < \c_zero
- \tex_advance:D \l_fp_output_integer_int \c_minus_one
- \tex_advance:D \l_fp_output_decimal_int \c_one_thousand_million
+ \exp_after:wN \__fp_sub_big_ii:wNww \__int_value:w
\fi:
\fi:
- \exp_after:wN \fp_trig_calc_Taylor:
- \fi:
+ \__int_eval:w #4 - #2 ; #1 #3; #5;
}
-\cs_new_protected_nopar:Npn \fp_tan:Nn { \fp_tan_aux:NNn \tl_set:Nn }
-\cs_new_protected_nopar:Npn \fp_gtan:Nn { \fp_tan_aux:NNn \tl_gset:Nn }
-\cs_generate_variant:Nn \fp_tan:Nn { c }
-\cs_generate_variant:Nn \fp_gtan:Nn { c }
-\cs_new_protected:Npn \fp_tan_aux:NNn #1#2#3
+\cs_new:Npn \__fp_sub_exponent_eq:nnnnnnnn #1#2#3#4 #5#6#7#8
{
- \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
- \tl_set:Nx \l_fp_arg_tl
- {
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- -
- \else:
- +
- \fi:
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_input_a_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_input_a_exponent_int
- }
- \if_int_compare:w \l_fp_input_a_exponent_int < -\c_five
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2 { \l_fp_arg_tl }
- }
+ \if_int_compare:w #1#2 > #5#6 \exp_stop_f:
+ \exp_after:wN \__fp_sub_big_i:wNww \__int_value:w
+ \else:
+ \if_int_compare:w #1#2 < #5#6 \exp_stop_f:
+ \exp_after:wN \__fp_sub_big_ii:wNww \__int_value:w
\else:
- \if_cs_exist:w
- c_fp_tan ( \l_fp_arg_tl ) _fp
- \cs_end:
+ \if_int_compare:w #3#4 > #7#8 \exp_stop_f:
+ \exp_after:wN \__fp_sub_big_i:wNww \__int_value:w
\else:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_tan_aux_i:
+ \if_int_compare:w #3#4 < #7#8 \exp_stop_f:
+ \exp_after:wN \__fp_sub_big_ii:wNww \__int_value:w
+ \else:
+ \exp_after:wN \__fp_sub_eq:wNww \__int_value:w
+ \fi:
\fi:
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2
- { \use:c { c_fp_tan ( \l_fp_arg_tl ) _fp } }
- }
\fi:
- \fp_tmp:w
+ \fi:
}
-\cs_new_protected_nopar:Npn \fp_tan_aux_i:
+\cs_new:Npn \__fp_sub_eq:wNww #1; #2 #3; #4;
+ { \exp_after:wN ; \exp_after:wN 1 \exp_after:wN ; }
+\cs_new:Npn \__fp_sub_big_i:wNww #1; #2 #3; #4;
+ {
+ \__fp_decimate:nNnnnn {#1}
+ \__fp_sub_back_mantissa:NnnwNnnnn
+ #4
+ #2
+ #3
+ }
+\cs_new:Npn \__fp_sub_big_ii:wNww #1; #2 #3; #4;
+ {
+ \exp_after:wN \__fp_sub_big_i:wNww
+ \__int_value:w #1 \exp_after:wN ;
+ \int_use:N \__int_eval:w 2 - #2 \__int_eval_end:
+ #4; #3;
+ }
+\cs_new:Npn \__fp_sub_back_mantissa:NnnwNnnnn #1 #2#3 #4; #5 #6#7#8#9
+ {
+ \exp_after:wN \__fp_sub_back_mantissa_i:NNwNNNNwN
+ \exp_after:wN #1
+ \exp_after:wN #5
+ \int_use:N \__int_eval:w 2#6#7 - #2 - \c_two +
+ \exp_after:wN \__fp_sub_back_mantissa_round:wNN
+ \int_use:N \__int_eval:w 2#8#9 - #3 ; #1 #5
+ }
+\cs_new:Npn \__fp_sub_back_mantissa_round:wNN #1; #2 #3
+ {
+ \exp_after:wN \__fp_sub_back_mantissa_iii:N
+ \__int_value:w
+ \exp_after:wN \__fp_round_neg:NNN
+ \exp_after:wN #3
+ \use_none:nnnnnnnn #1 #2
+ + #1
+ \exp_after:wN ;
+ }
+\cs_new:Npn \__fp_sub_back_mantissa_iii:N #1
+ {
+ \exp_after:wN \__fp_sub_back_mantissa_ii:NNNNNNw
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w
+ - #1
+ }
+\cs_new:Npn \__fp_sub_back_mantissa_ii:NNNNNNw #1 #2 #3#4#5#6 #7;
+ { #2 ; #1 {#3#4#5#6} {#7} ; }
+\cs_new:Npn \__fp_sub_back_mantissa_i:NNwNNNNwN #1#2 #3 #4#5#6#7 #8; #9
+ {
+ \if:w 0 #4
+ \exp_after:wN \__fp_sub_back_carry:NNwNnnnn
+ \exp_after:wN #1
+ \exp_after:wN #9
+ \fi:
+ ; #2
+ {#4#5#6#7} {#8}
+ }
+\cs_new:Npn \__fp_sub_back_carry:NNwNnnnn #1#2 ; #3 #4#5#6#7 ;
+ {
+ \exp_after:wN \__fp_sub_back_carry_i:wwN
+ \int_use:N \__int_eval:w #4 #5 - 1 + \exp_after:wN \__fp_use_s:n
+ \int_use:N \__int_eval:w 1 #6 #7 0 + #2 0 - #1 ; #3
+ }
+\cs_new:Npn \__fp_sub_back_carry_i:wwN #1 ;
{
- \if_int_compare:w \l_fp_input_a_exponent_int < \c_ten
- \exp_after:wN \fp_tan_aux_ii:
+ \if:w 0 #1
+ - 8
+ \exp_after:wN \__fp_sub_back_carry_small:wN \__int_value:w
\else:
- \cs_new_eq:cN { c_fp_tan ( \l_fp_arg_tl ) _fp }
- \c_zero_fp
- \exp_after:wN \fp_trig_overflow_msg:
+ - \__fp_sub_back_carry_ii:NNNNNNNNw #1 1234567;
+ \exp_after:wN \__fp_sub_back_carry_large:NNNNNNNNw
+ \fi:
+ #1
+ }
+\cs_new:Npn \__fp_sub_back_carry_ii:NNNNNNNNw #1#2#3#4#5#6#7#8#9; {#8}
+\cs_new:Npn \__fp_sub_back_carry_large:NNNNNNNNw #1#2#3#4 #5#6#7#8 #9;
+ {
+ \__fp_sub_back_carry_large_ii:NNNNNNNNw
+ #9 000000 ; {#1#2#3#4} {#5#6#7#8}
+ }
+\cs_new:Npn \__fp_sub_back_carry_large_ii:NNNNNNNNw #1#2#3#4 #5#6#7#8 #9;
+ { \__fp_sub_back_carry_large_iii:nnnnN {#1#2#3#4} {#5#6#7#8} }
+\cs_new:Npn \__fp_sub_back_carry_large_iii:nnnnN #1#2 #3#4 #5
+ { ; #5 {#3}{#4} {#1}{#2} ; }
+\cs_new:Npn \__fp_sub_back_carry_small:wN #1;
+ {
+ - \exp_after:wN \__fp_use_i_until_s:nw
+ \use_none:nnnnnnnnn #1 012345678;
+ \__fp_sub_back_carry_small_ii:NNNNNNNN #1 00000000 ;
+ }
+\cs_new:Npn \__fp_sub_back_carry_small_ii:NNNNNNNN #1#2#3#4 #5#6#7#8
+ { \__fp_sub_back_carry_small_iii:nnNwN {#1#2#3#4} {#5#6#7#8} }
+\cs_new:Npn \__fp_sub_back_carry_small_iii:nnNwN #1 #2 #3 #4; #5
+ { ; #5 {#1} {#2} {#3000} {0000} ; }
+\cs_new:cpn { __fp_*_o:ww }
+ \s__fp \__fp_chk:w #1 #2 #3 ; \s__fp \__fp_chk:w #4 #5
+ { \__fp_mul_cases:NN #1 #4 #2 #5 #3 ; }
+\cs_new:Npn \__fp_mul_cases:NN #1 #2
+ {
+ \if_case:w \if_meaning:w 1 #1 #2 \else:
+ \if_meaning:w 1 #2 #1 \else:
+ \if_meaning:w #1#2 #1 \else:
+ \if_int_compare:w \__int_eval:w #1 + #2 > \c_two
+ 3 \else: 4 \fi: \fi: \fi: \fi:
+ \exp_stop_f:
+ \exp_after:wN \__fp_basics_return_zero:NNww
+ \or: \exp_after:wN \__fp_mul_normal:NNww
+ \or: \exp_after:wN \__fp_basics_return_inf:NNww
+ \or: \exp_after:wN \__fp_basics_return_nan:NNww
+ \or:
+ \exp_after:wN \__fp_mul_invalid:NNNNww
+ \exp_after:wN #1
+ \exp_after:wN #2
\fi:
}
-\cs_new_protected_nopar:Npn \fp_tan_aux_ii:
+\cs_new:Npn \__fp_mul_invalid:NNNNww #1#2#3#4#5; #6;
{
- \fp_trig_normalise:
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- \if_int_compare:w \l_fp_trig_octant_int > \c_two
- \l_fp_output_sign_int \c_minus_one
- \else:
- \l_fp_output_sign_int \c_one
- \fi:
+ \__fp_invalid_operation:Nnww \c_nan_fp { * }
+ \s__fp \__fp_chk:w #1 #3 #5 ;
+ \s__fp \__fp_chk:w #2 #4 #6 ;
+ }
+\cs_new:Npn \__fp_mul_normal:NNww #1#2
+ {
+ \if:w #1#2
+ \exp_after:wN \__fp_mul_npos:Nnwnw
+ \exp_after:wN 0
\else:
- \if_int_compare:w \l_fp_trig_octant_int > \c_two
- \l_fp_output_sign_int \c_one
- \else:
- \l_fp_output_sign_int \c_minus_one
- \fi:
+ \exp_after:wN \__fp_mul_npos:Nnwnw
+ \exp_after:wN 2
\fi:
- \fp_cos_aux_ii:
- \if_int_compare:w \l_fp_input_a_decimal_int = \c_zero
- \if_int_compare:w \l_fp_input_a_integer_int = \c_zero
- \cs_new_eq:cN { c_fp_tan ( \l_fp_arg_tl ) _fp }
- \c_undefined_fp
- \else:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_tan_aux_iii:
- \fi:
- \else:
- \exp_after:wN \fp_tan_aux_iii:
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_tan_aux_iii:
- {
- \l_fp_input_b_integer_int \l_fp_output_decimal_int
- \l_fp_input_b_decimal_int \l_fp_output_extended_int
- \l_fp_input_b_exponent_int -\c_nine
- \fp_standardise:NNNN
- \l_fp_input_b_sign_int
- \l_fp_input_b_integer_int
- \l_fp_input_b_decimal_int
- \l_fp_input_b_exponent_int
- \fp_sin_aux_ii:
- \l_fp_input_a_integer_int \l_fp_output_decimal_int
- \l_fp_input_a_decimal_int \l_fp_output_extended_int
- \l_fp_input_a_exponent_int -\c_nine
- \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
- \if_int_compare:w \l_fp_input_a_decimal_int = \c_zero
- \if_int_compare:w \l_fp_input_a_integer_int = \c_zero
- \cs_new_eq:cN { c_fp_tan ( \l_fp_arg_tl ) _fp }
- \c_zero_fp
- \else:
- \exp_after:wN \exp_after:wN \exp_after:wN \fp_tan_aux_iv:
- \fi:
- \else:
- \exp_after:wN \fp_tan_aux_iv:
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_tan_aux_iv:
- {
- \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:
- \l_fp_div_offset_int \c_one_hundred_million
- \fp_div_loop:
- \l_fp_output_exponent_int
- \int_eval:w
- \l_fp_input_a_exponent_int - \l_fp_input_b_exponent_int
- \int_eval_end:
- \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_tan ( \l_fp_arg_tl ) _fp }
- \tl_gset:cx { c_fp_tan ( \l_fp_arg_tl ) _fp }
- {
- \if_int_compare:w \l_fp_output_sign_int > \c_zero
- +
- \else:
- -
- \fi:
- \int_use:N \l_fp_output_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_output_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_output_exponent_int
- }
}
-\tl_const:cn { c_fp_exp_1_tl } { { 2 } { 718281828 } { 459045235 } { 0 } }
-\tl_const:cn { c_fp_exp_2_tl } { { 7 } { 389056098 } { 930650227 } { 0 } }
-\tl_const:cn { c_fp_exp_3_tl } { { 2 } { 008553692 } { 318766774 } { 1 } }
-\tl_const:cn { c_fp_exp_4_tl } { { 5 } { 459815003 } { 314423908 } { 1 } }
-\tl_const:cn { c_fp_exp_5_tl } { { 1 } { 484131591 } { 025766034 } { 2 } }
-\tl_const:cn { c_fp_exp_6_tl } { { 4 } { 034287934 } { 927351226 } { 2 } }
-\tl_const:cn { c_fp_exp_7_tl } { { 1 } { 096633158 } { 428458599 } { 3 } }
-\tl_const:cn { c_fp_exp_8_tl } { { 2 } { 980957987 } { 041728275 } { 3 } }
-\tl_const:cn { c_fp_exp_9_tl } { { 8 } { 103083927 } { 575384008 } { 3 } }
-\tl_const:cn { c_fp_exp_10_tl } { { 2 } { 202646579 } { 480671652 } { 4 } }
-\tl_const:cn { c_fp_exp_20_tl } { { 4 } { 851651954 } { 097902280 } { 8 } }
-\tl_const:cn { c_fp_exp_30_tl } { { 1 } { 068647458 } { 152446215 } { 13 } }
-\tl_const:cn { c_fp_exp_40_tl } { { 2 } { 353852668 } { 370199854 } { 17 } }
-\tl_const:cn { c_fp_exp_50_tl } { { 5 } { 184705528 } { 587072464 } { 21 } }
-\tl_const:cn { c_fp_exp_60_tl } { { 1 } { 142007389 } { 815684284 } { 26 } }
-\tl_const:cn { c_fp_exp_70_tl } { { 2 } { 515438670 } { 919167006 } { 30 } }
-\tl_const:cn { c_fp_exp_80_tl } { { 5 } { 540622384 } { 393510053 } { 34 } }
-\tl_const:cn { c_fp_exp_90_tl } { { 1 } { 220403294 } { 317840802 } { 39 } }
-\tl_const:cn { c_fp_exp_100_tl } { { 2 } { 688117141 } { 816135448 } { 43 } }
-\tl_const:cn { c_fp_exp_200_tl } { { 7 } { 225973768 } { 125749258 } { 86 } }
-\tl_const:cn { c_fp_exp_-1_tl } { { 3 } { 678794411 } { 71442322 } { -1 } }
-\tl_const:cn { c_fp_exp_-2_tl } { { 1 } { 353352832 } { 366132692 } { -1 } }
-\tl_const:cn { c_fp_exp_-3_tl } { { 4 } { 978706836 } { 786394298 } { -2 } }
-\tl_const:cn { c_fp_exp_-4_tl } { { 1 } { 831563888 } { 873418029 } { -2 } }
-\tl_const:cn { c_fp_exp_-5_tl } { { 6 } { 737946999 } { 085467097 } { -3 } }
-\tl_const:cn { c_fp_exp_-6_tl } { { 2 } { 478752176 } { 666358423 } { -3 } }
-\tl_const:cn { c_fp_exp_-7_tl } { { 9 } { 118819655 } { 545162080 } { -4 } }
-\tl_const:cn { c_fp_exp_-8_tl } { { 3 } { 354626279 } { 025118388 } { -4 } }
-\tl_const:cn { c_fp_exp_-9_tl } { { 1 } { 234098040 } { 866795495 } { -4 } }
-\tl_const:cn { c_fp_exp_-10_tl } { { 4 } { 539992976 } { 248451536 } { -5 } }
-\tl_const:cn { c_fp_exp_-20_tl } { { 2 } { 061153622 } { 438557828 } { -9 } }
-\tl_const:cn { c_fp_exp_-30_tl } { { 9 } { 357622968 } { 840174605 } { -14 } }
-\tl_const:cn { c_fp_exp_-40_tl } { { 4 } { 248354255 } { 291588995 } { -18 } }
-\tl_const:cn { c_fp_exp_-50_tl } { { 1 } { 928749847 } { 963917783 } { -22 } }
-\tl_const:cn { c_fp_exp_-60_tl } { { 8 } { 756510762 } { 696520338 } { -27 } }
-\tl_const:cn { c_fp_exp_-70_tl } { { 3 } { 975449735 } { 908646808 } { -31 } }
-\tl_const:cn { c_fp_exp_-80_tl } { { 1 } { 804851387 } { 845415172 } { -35 } }
-\tl_const:cn { c_fp_exp_-90_tl } { { 8 } { 194012623 } { 990515430 } { -40 } }
-\tl_const:cn { c_fp_exp_-100_tl } { { 3 } { 720075976 } { 020835963 } { -44 } }
-\tl_const: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: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
- {
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- -
- \else:
- +
- \fi:
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_input_a_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_input_a_exponent_int
- }
- \if_cs_exist:w c_fp_exp ( \l_fp_arg_tl ) _fp \cs_end:
- \else:
- \exp_after:wN \fp_exp_internal:
- \fi:
- \cs_set_protected_nopar:Npx \fp_tmp:w
- {
- \group_end:
- #1 \exp_not:N #2
- {
- \if_cs_exist:w c_fp_exp ( \l_fp_arg_tl ) _fp
- \cs_end:
- \use:c { c_fp_exp ( \l_fp_arg_tl ) _fp }
- \else:
- \c_zero_fp
- \fi:
- }
- }
- \fp_tmp:w
+\cs_new:Npn \__fp_mul_npos:Nnwnw #1 #2#3; #4 #5;
+ {
+ \exp_after:wN \__fp_sanitize:Nw
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w
+ #2 + #4
+ \__fp_mul_mantissa:nnnnNnnnn #3 #1 #5
+ \exp_after:wN ;
+ }
+\cs_new:Npn \__fp_mul_mantissa:nnnnNnnnn #1#2#3#4 #5 #6#7#8#9
+ {
+ \exp_after:wN \__fp_mul_mantissa_after:NNN
+ \exp_after:wN #5
+ \int_use:N \__int_eval:w 99990000 + #1*#6 +
+ \exp_after:wN \__fp_mul_mantissa_keep:NNNNNw
+ \int_use:N \__int_eval:w 99990000 + #1*#7 + #2*#6 +
+ \exp_after:wN \__fp_mul_mantissa_keep:NNNNNw
+ \int_use:N \__int_eval:w 99990000 + #1*#8 + #2*#7 + #3*#6 +
+ \exp_after:wN \__fp_mul_mantissa_drop:NNNNNw
+ \int_use:N \__int_eval:w 99990000 + #1*#9 + #2*#8 + #3*#7 + #4*#6 +
+ \exp_after:wN \__fp_mul_mantissa_drop:NNNNNw
+ \int_use:N \__int_eval:w 99990000 + #2*#9 + #3*#8 + #4*#7 +
+ \exp_after:wN \__fp_mul_mantissa_drop:NNNNNw
+ \int_use:N \__int_eval:w 99990000 + #3*#9 + #4*#8 +
+ \exp_after:wN \__fp_mul_mantissa_drop:NNNNNw
+ \int_use:N \__int_eval:w 100000000 + #4*#9 \exp_after:wN ;
+ }
+\cs_new:Npn \__fp_mul_mantissa_drop:NNNNNw #1#2#3#4#5 #6;
+ { #1#2#3#4#5 ; + #6 }
+\cs_new:Npn \__fp_mul_mantissa_keep:NNNNNw #1#2#3#4#5 #6;
+ { #1#2#3#4#5 ; #6 ; }
+\cs_new:Npn \__fp_mul_mantissa_after:NNN #1 #2 #3
+ {
+ \if:w 0 #3
+ \exp_after:wN \__fp_mul_mantissa_small:NNwwwN
+ \else:
+ \exp_after:wN \__fp_mul_mantissa_large:NwwNNNN
+ \fi:
+ #1 #3
}
-\cs_new_protected_nopar:Npn \fp_exp_internal:
+\cs_new:Npn \__fp_mul_mantissa_large:NwwNNNN #1 #2; #3; #4#5#6#7; +
{
- \if_int_compare:w \l_fp_input_a_exponent_int < \c_three
- \fp_extended_normalise:
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- \if_int_compare:w \l_fp_input_a_integer_int < 230 \scan_stop:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \fp_exp_aux:
- \else:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \fp_exp_overflow_msg:
+ \exp_after:wN \__fp_basics_pack_high:NNNNNw
+ \int_use:N \__int_eval:w 1#2
+ \exp_after:wN \__fp_basics_pack_low:NNNNNw
+ \int_use:N \__int_eval:w 1#3#4#5#6#7 + \__fp_round_s:NNNw #1 #7
+ }
+\cs_new:Npn \__fp_mul_mantissa_small:NNwwwN #1 #2#3; #4; #5; + #6
+ {
+ - \c_one
+ \exp_after:wN \__fp_basics_pack_high:NNNNNw
+ \int_use:N \__int_eval:w 1#3
+ \exp_after:wN \__fp_mul_mantissa_small_pack:NNNNNNw
+ \int_use:N \__int_eval:w 1#4#5#6 + \__fp_round_s:NNNw #1 #6
+ }
+\cs_new:Npn \__fp_mul_mantissa_small_pack:NNNNNNw #1#2 #3#4#5#6 #7;
+ {
+ #2
+ \if:w 2 #1
+ + \c_ten
+ \fi:
+ ; {#3#4#5#6} {#7} ;
+ }
+\cs_new:cpn { __fp_/_o:ww }
+ \s__fp \__fp_chk:w #1 #2 #3 ; \s__fp \__fp_chk:w #4 #5 #6 ;
+ { \__fp_div_back_cases:NN #4 #1 #5 #2 #6 ; #3 ; }
+\cs_new:Npn \__fp_div_back_cases:NN #1 #2
+ {
+ \if_case:w \if_int_compare:w #1 = #2 \exp_stop_f:
+ #1 \exp_stop_f:
+ \else:
+ \if_int_compare:w #1 < #2 \exp_stop_f:
+ \if:w 3 #2 \c_four \else: \c_five \fi:
+ \else:
+ \if:w 3 #1 \c_six \else: \c_seven \fi:
+ \fi:
+ \fi:
+ \exp_after:wN \__fp_div_back_invalid:NNNww \exp_after:wN 0
+ \or: \exp_after:wN \__fp_div_back_normal:NNww
+ \or: \exp_after:wN \__fp_div_back_invalid:NNNww \exp_after:wN 2
+ \or: \exp_after:wN \__fp_basics_return_nan_nan:NNww
+ \or:
+ \exp_after:wN \__fp_basics_return_ii:NNNNww
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \or: \exp_after:wN \__fp_basics_return_inf:NNww
+ \or:
+ \exp_after:wN \__fp_basics_return_i:NNNNww
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \or: \exp_after:wN \__fp_basics_return_zero:NNww
+ \fi:
+ }
+\cs_new:Npn \__fp_div_back_invalid:NNNww #1#2#3 #4; #5;
+ {
+ \__fp_invalid_operation:Nnww \c_nan_fp { / }
+ \s__fp \__fp_chk:w #1 #3 #5 ;
+ \s__fp \__fp_chk:w #1 #2 #4 ;
+ }
+\cs_new:Npn \__fp_div_back_normal:NNww #1#2
+ {
+ \if:w #1#2
+ \exp_after:wN \__fp_div_back_npos:Nnwnw
+ \exp_after:wN 0
+ \else:
+ \exp_after:wN \__fp_div_back_npos:Nnwnw
+ \exp_after:wN 2
+ \fi:
+ }
+\cs_new:Npn \__fp_div_back_npos:Nnwnw #1 #2 #3#4#5#6; #7 #8;
+ {
+ \exp_after:wN \__fp_sanitize:Nw
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w
+ #7 - #2
+ \__fp_div_mantissa_i:wNwnn #3; #4;
+ #8 {#3}{#4}{#5}{#6} #1
+ }
+\cs_new:Npn \__fp_div_mantissa_i:wNwnn #1; #2 #3; #4 #5
+ {
+ \exp_after:wN \__fp_div_mantissa_ii:ww
+ \int_use:N \__int_eval:w #1#2 + \c_one ;
+ #4 #5 ;
+ }
+\cs_new:Npn \__fp_div_mantissa_ii:ww #1; #2;
+ {
+ \exp_after:wN \__fp_div_mantissa_iii:www
+ \__int_value:w #1 \exp_after:wN ;
+ \__int_value:w
+ \exp_after:wN \__fp_div_mantissa_calc:Nwwnnnnnn
+ \int_use:N \__int_eval:w #20/#1 + 999999 ; #2 ;
+ }
+\cs_new:Npn \__fp_div_mantissa_calc:Nwwnnnnnn 1#1#2; #3;#4#5 #6#7#8#9
+ {
+ 1 #1 #2 \exp_after:wN ;
+ \int_use:N \__int_eval:w
+ - 200000 + #3 - #2 * #6
+ \if_meaning:w 1 #1
+ - #6#70
+ \fi:
+ +
+ \exp_after:wN \__fp_div_mantissa_calc_last:NNNNNN
+ \int_use:N \__int_eval:w
+ 1999800000 + #4 - #2*#7
+ \if_meaning:w 1 #1
+ - #80
+ \fi:
+ +
+ \exp_after:wN \__fp_div_mantissa_calc_pack:NNNNNNw
+ \int_use:N \__int_eval:w
+ 1999800000 + #5 - #2*#8
+ \if_meaning:w 1 #1
+ - #90
\fi:
+ +
+ \exp_after:wN \__fp_div_mantissa_calc_pack:NNNNNNw
+ \int_use:N \__int_eval:w 2000000000 - #2*#9 ;
+ {#6}{#7}{#8}{#9}
+ }
+\cs_new:Npn \__fp_div_mantissa_calc_pack:NNNNNNw #1#2#3#4#5#6 #7;
+ { #1#2#3#4#5#6 ; {#7} }
+\cs_new:Npn \__fp_div_mantissa_calc_last:NNNNNN #1#2#3#4#5#6
+ { #1#2#3#4#5#6 \__int_eval_end: }
+\cs_new:Npn \__fp_div_mantissa_iii:www #1; #2; #3;
+ {
+ \exp_after:wN \__fp_div_mantissa_iii_after:w
+ \int_use:N \__int_eval:w #2
+ \exp_after:wN \__fp_div_mantissa_iv:www
+ \__int_value:w #1 \exp_after:wN ;
+ \__int_value:w
+ \exp_after:wN \__fp_div_mantissa_calc:Nwwnnnnnn
+ \int_use:N \__int_eval:w #30/#1 + 999999 ;
+ #3 ;
+ }
+\cs_new:Npn \__fp_div_mantissa_iv:www #1; #2; #3;
+ {
+ \exp_after:wN \__fp_div_mantissa_pack:NNN
+ \int_use:N \__int_eval:w #2
+ \exp_after:wN \__fp_div_mantissa_v:www
+ \__int_value:w #1 \exp_after:wN ;
+ \__int_value:w
+ \exp_after:wN \__fp_div_mantissa_calc:Nwwnnnnnn
+ \int_use:N \__int_eval:w #30/#1 + 999999 ;
+ #3 ;
+ }
+\cs_new:Npn \__fp_div_mantissa_v:www #1; #2; #3;
+ {
+ \exp_after:wN \__fp_div_mantissa_pack:NNN
+ \int_use:N \__int_eval:w #2
+ \exp_after:wN \__fp_div_mantissa_vi:wwnnnn
+ \__int_value:w
+ \exp_after:wN \__fp_div_mantissa_calc:Nwwnnnnnn
+ \int_use:N \__int_eval:w #30/#1 + 999999 ;
+ #3 ;
+ }
+\cs_new:Npn \__fp_div_mantissa_vi:wwnnnn #1; #2;#3#4 #5#6
+ {
+ \exp_after:wN \__fp_div_mantissa_pack:NNN
+ \int_use:N \__int_eval:w #10
+ \exp_after:wN \__fp_div_mantissa_vii:wwnnnnnn
+ \int_use:N \__int_eval:w (\c_two*#2)/#5#6 ; % <- P
+ #2;{#3}{#4}
+ {#5}{#6}
+ }
+\cs_new:Npn \__fp_div_mantissa_vii:wwnnnnnn #1; #2;#3#4 #5#6#7#8
+ {
+ + \c_five * #1
+ \exp_after:wN \__fp_div_mantissa_ix:Nww
+ \int_use:N \__int_eval:w -20 + 2*#2 - #1*#5#6 +
+ \exp_after:wN \__fp_div_mantissa_viii:NNw
+ \int_use:N \__int_eval:w 199980 + 2*#3 - #1*#7 +
+ \exp_after:wN \__fp_div_mantissa_viii:NNw
+ \int_use:N \__int_eval:w 200000 + 2*#4 - #1*#8 ; ;
+ }
+\cs_new:Npn \__fp_div_mantissa_viii:NNw #1#2#3; { #1#2 ; + #3 }
+\cs_new:Npn \__fp_div_mantissa_ix:Nww #1#2;#3;
+ {
+ \if_meaning:w 0 #1
+ \exp_after:wN \__fp_div_mantissa_x:w
+ \int_use:N \__int_eval:w #3
+ \else:
+ \if_meaning:w - #1
+ -
\else:
- \if_int_compare:w \l_fp_input_a_integer_int < 230 \scan_stop:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \fp_exp_aux:
- \else:
- \fp_exp_const:cx { c_fp_exp ( \l_fp_arg_tl ) _fp }
- { \c_zero_fp }
- \fi:
+ +
\fi:
- \else:
- \exp_after:wN \fp_exp_overflow_msg:
+ \c_one
\fi:
+ ;
}
-\cs_new_protected_nopar:Npn \fp_exp_aux:
+\cs_new:Npn \__fp_div_mantissa_x:w #1;
{
- \if_int_compare:w \l_fp_input_a_integer_int > \c_zero
- \exp_after:wN \fp_exp_integer:
+ \if_int_compare:w #1 > \c_zero
+ + \c_one
+ \fi:
+ ;
+ }
+\cs_new:Npn \__fp_div_mantissa_pack:NNN 1 #1 #2 { + #1 #2 ; }
+\cs_new:Npn \__fp_div_mantissa_iii_after:w 10 #1
+ {
+ \if_meaning:w 0 #1
+ \exp_after:wN \__fp_div_mantissa_small:wwwNNNNwN
\else:
- \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
- \exp_after:wN \fp_exp_decimal:
+ \exp_after:wN \__fp_div_mantissa_large:wwwNNNNwN
\fi:
+ #1
}
-\cs_new_protected_nopar:Npn \fp_exp_integer:
+\cs_new:Npn \__fp_div_mantissa_small:wwwNNNNwN
+ 0 #1; #2; #3; #4#5#6#7#8; #9
+ {
+ \exp_after:wN \__fp_basics_pack_high:NNNNNw
+ \int_use:N \__int_eval:w 1 #1#2
+ \exp_after:wN \__fp_basics_pack_low:NNNNNw
+ \int_use:N \__int_eval:w 1 #3#4#5#6#7
+ + \__fp_round:NNN #9 #7 #8
+ \exp_after:wN ;
+ }
+\cs_new:Npn \__fp_div_mantissa_large:wwwNNNNwN
+ #1; #2; #3; #4#5#6#7#8; #9
+ {
+ + \c_one
+ \exp_after:wN \__fp_div_mantissa_large_pack:NNNNNNNNw
+ \int_use:N \__int_eval:w 1 #1 #2 %<- 1+9d
+ \exp_after:wN \__fp_add_mantissa_carry_pack_ii:NNNNw
+ \int_use:N \__int_eval:w 1 #3 #4 #5 #6
+ + \__fp_round:NNNN #9 #6 #7 #8
+ \exp_after:wN ;
+ }
+\cs_new:Npn \__fp_div_mantissa_large_pack:NNNNNNNNw
+ 1 #1#2#3#4 #5#6#7#8 #9; { ; {#1#2#3#4} {#5#6#7#8} {#9} }
+\cs_new:Npn \__fp_neg:w \s__fp \__fp_chk:w #1 #2
+ {
+ \exp_after:wN \__fp_exp_after_o:w
+ \exp_after:wN \s__fp
+ \exp_after:wN \__fp_chk:w
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w \c_two - #2 \__int_eval_end:
+ }
+\cs_new:Npn \__fp_abs:w \s__fp \__fp_chk:w #1 #2
+ { \__fp_exp_after_o:w \s__fp \__fp_chk:w #1 0 }
+%% File: l3fp-extended.dtx Copyright (C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\tl_const:Nn \c__fp_one_fixed_tl
+ { {10000} {0000} {0000} {0000} {0000} {0000} }
+\cs_new:Npn \__fp_fixed_continue:wn #1; #2 { #2 #1; }
+\cs_new:Npn \__fp_fixed_div_int:wwN #1#2#3#4#5#6 ; #7 ; #8
+ {
+ \exp_after:wN \__fp_fixed_div_int_after:Nw
+ \exp_after:wN #8
+ \int_use:N \__int_eval:w \c_minus_one
+ \__fp_fixed_div_int_i:wnN
+ #1; {#7} \__fp_fixed_div_int_ii:wnn
+ #2; {#7} \__fp_fixed_div_int_ii:wnn
+ #3; {#7} \__fp_fixed_div_int_ii:wnn
+ #4; {#7} \__fp_fixed_div_int_ii:wnn
+ #5; {#7} \__fp_fixed_div_int_ii:wnn
+ #6; {#7} \__fp_fixed_div_int_end:wnn ;
+ }
+\cs_new:Npn \__fp_fixed_div_int_i:wnN #1; #2 #3
+ {
+ \exp_after:wN #3
+ \int_use:N \__int_eval:w #1 / #2 - \c_one ;
+ {#2}
+ {#1}
+ }
+\cs_new:Npn \__fp_fixed_div_int_ii:wnn #1; #2 #3
+ {
+ + #1
+ \exp_after:wN \__fp_fixed_div_int_pack:Nw
+ \int_use:N \__int_eval:w 9999
+ \exp_after:wN \__fp_fixed_div_int_i:wnN
+ \int_use:N \__int_eval:w #3 - #1*#2 \__int_eval_end:
+ }
+\cs_new:Npn \__fp_fixed_div_int_end:wnn #1; #2 #3 { + #1 + \c_two ; }
+\cs_new:Npn \__fp_fixed_div_int_pack:Nw #1 #2; { + #1; {#2} }
+\cs_new:Npn \__fp_fixed_div_int_after:Nw #1 #2; { #1 {#2} }
+\cs_new:Npn \__fp_fixed_add_one:wN #1#2; #3
+ {
+ \exp_after:wN #3 \exp_after:wN
+ { \int_use:N \__int_eval:w 10000 + #1 } #2 ;
+ }
+\cs_new_nopar:Npn \__fp_fixed_add:wwN { \__fp_fixed_add_i:NNnnnnwnn + + }
+\cs_new_nopar:Npn \__fp_fixed_sub:wwN { \__fp_fixed_add_i:NNnnnnwnn + - }
+\cs_new_nopar:Npn \__fp_fixed_sub_back:wwN { \__fp_fixed_add_i:NNnnnnwnn - + }
+\cs_new:Npn \__fp_fixed_add_i:NNnnnnwnn #1#2 #3#4#5#6 #7; #8#9
+ {
+ \exp_after:wN \__fp_fixed_add_after:NNNNNwN
+ \int_use:N \__int_eval:w 1 9999 9998 #1 #3#4 #2 #8#9
+ \exp_after:wN \__fp_fixed_add_pack:NNNNNwN
+ \int_use:N \__int_eval:w 1 9999 9998 #1 #5#6
+ \__fp_fixed_add_ii:NnnNnnnnw #1 #7 #2
+ }
+\cs_new:Npn \__fp_fixed_add_ii:NnnNnnnnw #1 #2#3 #4 #5#6 #7#8 ; #9
+ {
+ #4 #5#6
+ \exp_after:wN \__fp_fixed_add_pack:NNNNNwN
+ \int_use:N \__int_eval:w 2 0000 0000 #4 #7#8 #1 #2#3 ; #9 ;
+ }
+\cs_new:Npn \__fp_fixed_add_pack:NNNNNwN #1 #2#3#4#5 #6; #7
+ { + #1 ; #7 {#2#3#4#5} {#6} }
+\cs_new:Npn \__fp_fixed_add_after:NNNNNwN #1 #2#3#4#5 #6; #7
+ {
+ \exp_after:wN #7
+ \exp_after:wN { \int_use:N \__int_eval:w - 2 0000 + #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:wwn
+ \int_use:N \__int_eval:w \c__fp_leading_shift_int
+ \exp_after:wN \__fp_pack:NNNNNw
+ \int_use:N \__int_eval:w \c__fp_middle_shift_int
+ + #1*#6
+ \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:NNNNNw
+ \int_use:N \__int_eval:w \c__fp_middle_shift_int
+ + #1*#8 + #2*#7 + #3*#6
+ \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: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_i:nnnnnnnn #5 {#6}{#7} {#1}{#2}
+ }
+\cs_new:Npn \__fp_fixed_mul_i:nnnnnnnn #1#2 #3#4 #5#6 #7#8
+ { #1*#4 + #2*#3 + #5*#8 + #6*#7 )/10000 + #1*#3 + #5*#7 ; }
+\cs_new:Npn \__fp_fixed_mul_pack:NNNNNw
+ #1 #2#3#4#5 #6; { + #1#2#3#4#5 ; {#6} }
+\cs_new:Npn \__fp_fixed_mul_after:wwn #1; #2; #3 { #3 {#1} #2 ; }
+\cs_new:Npn \__fp_fixed_one_minus_mul:wwn #1; #2#3#4#5;
+ {
+ \exp_after:wN \__fp_fixed_mul_after:wwn
+ \int_use:N \__int_eval:w \c__fp_big_leading_shift_int + \c_ten_thousand
+ \exp_after:wN \__fp_pack_big:NNNNNNw
+ \int_use:N \__int_eval:w \c__fp_big_middle_shift_int
+ \__fp_fixed_mul_add_i:Nnwnnwnnn
+ - 00; {#2}{#3}{#4}; #1; {#2}{#3}{#4}#5; - 00 ;
+ }
+\cs_new:Npn \__fp_fixed_mul_add:wwwn #1; #2#3#4#5; #6#7#8#9
+ {
+ \exp_after:wN \__fp_fixed_mul_after:wwn
+ \int_use:N \__int_eval:w \c__fp_big_leading_shift_int + #6
+ \exp_after:wN \__fp_pack_big:NNNNNNw
+ \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + #7
+ \__fp_fixed_mul_add_i:Nnwnnwnnn
+ + {#8}{#9}; {#2}{#3}{#4}; #1; {#2}{#3}{#4}#5; +
+ }
+\cs_new:Npn \__fp_fixed_mul_sub_back:wwwn #1; #2#3#4#5; #6#7#8#9
+ {
+ \exp_after:wN \__fp_fixed_mul_after:wwn
+ \int_use:N \__int_eval:w \c__fp_big_leading_shift_int + #6
+ \exp_after:wN \__fp_pack_big:NNNNNNw
+ \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + #7
+ \__fp_fixed_mul_add_i:Nnwnnwnnn
+ - {#8}{#9}; {#2}{#3}{#4}; #1; {#2}{#3}{#4}#5; -
+ }
+\cs_new:Npn \__fp_fixed_mul_add_i:Nnwnnwnnn #1 #2#3; #4#5#6; #7#8#9
+ { % sg z3z4; y1y2y3; x1x2x3 x4x5x6; y1y2y3y4y5y6; sg z5z6;
+ #1 #7*#4
+ \exp_after:wN \__fp_pack_big:NNNNNNw
+ \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + #2
+ #1 #7*#5 #1 #8*#4
+ \exp_after:wN \__fp_pack_big:NNNNNNw
+ \int_use:N \__int_eval:w \c__fp_big_middle_shift_int + #3
+ #1 #7*#6 #1 #8*#5 #1 #9*#4
+ \exp_after:wN \__fp_pack_big:NNNNNNw
+ \int_use:N \__int_eval:w \c__fp_big_middle_shift_int
+ #1 \__fp_fixed_mul_add_ii:nnnnwnnnn {#7}{#8}{#9}
+ }
+\cs_new:Npn \__fp_fixed_mul_add_ii:nnnnwnnnn #1#2#3#4#5; #6#7#8#9
+ { % x1x2x3x4 x5x6; y1y2y3y4 y5y6; sg z5z6;
+ ( #1*#9 + #2*#8 + #3*#7 + #4*#6 )
+ \exp_after:wN \__fp_pack_big:NNNNNNw
+ \int_use:N \__int_eval:w \c__fp_big_trailing_shift_int
+ \__fp_fixed_mul_add_iii:nnnnwnnwN
+ { #6 + #4*#7 + #3*#8 + #2*#9 + #1 }
+ { #7 + #4*#8 + #3*#9 + #2 }
+ {#1} #5;
+ {#6}
+ }
+\cs_new:Npn \__fp_fixed_mul_add_iii:nnnnwnnwN #1#2 #3#4#5; #6#7#8; #9
+ { % {y1+x4*y2+x3*y3+x2*y4+x1} {y2+x4*y3+x3*y4+x2}
+ % x1x5x6; y1y5y6; sg z5z6;
+ % =>
+ % sg (x5*y1+x4*y2+x3*y3+x2*y4+x1*y5)
+ % sg (x6*y1+x5*y2+x4*y3+x3*y4+x2*y5+x1*y6)/10000
+ % + z5z6;
+ #9 (#4* #1 *#7)
+ #9 (#5*#6+#4* #2 *#7+#3*#8) / \c_ten_thousand
+ + \__fp_use_s:nn
+ }
+\cs_new:Npn \__fp_fixed_to_float:Nw #1#2; { \__fp_fixed_to_float:wN #2; #1 }
+\cs_new:Npn \__fp_fixed_to_float:wN #1#2#3#4#5#6; #7
+ {
+ + \c_four % for the 8-digit-at-the-start thing.
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_fixed_to_loop:N
+ \exp_after:wN \use_none:n
+ \int_use:N \__int_eval:w
+ 1 0000 0000 + #1 \exp_after:wN \__fp_use_none_stop_f:n
+ \__int_value:w 1#2 \exp_after:wN \__fp_use_none_stop_f:n
+ \__int_value:w 1#3#4 \exp_after:wN \__fp_use_none_stop_f:n
+ \__int_value:w 1#5#6
+ \exp_after:wN ;
+ \exp_after:wN ;
+ }
+\cs_new:Npn \__fp_fixed_to_loop:N #1
+ {
+ \if_meaning:w 0 #1
+ - \c_one
+ \exp_after:wN \__fp_fixed_to_loop:N
+ \else:
+ \exp_after:wN \__fp_fixed_to_loop_end:w
+ \exp_after:wN #1
+ \fi:
+ }
+\cs_new:Npn \__fp_fixed_to_loop_end:w #1 #2 ;
{
- \if_int_compare:w \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
- \exp_after:wN \fp_exp_integer_tens:
+ \if_meaning:w ; #1
+ \exp_after:wN \__fp_fixed_to_float_zero:w
\else:
- \tl_set:Nx \l_fp_internal_tl
- {
- \exp_after:wN \use_i:nnn
- \int_use:N \l_fp_input_a_integer_int
- }
- \l_fp_input_a_integer_int
- \int_eval:w
- \l_fp_input_a_integer_int - \l_fp_internal_tl 00
- \int_eval_end:
- \if_int_compare:w \l_fp_input_a_sign_int < \c_zero
- \if_int_compare:w \l_fp_output_integer_int > 200 \scan_stop:
- \fp_exp_const:cx { c_fp_exp ( \l_fp_arg_tl ) _fp }
- { \c_zero_fp }
- \else:
- \fp_exp_integer_const:n { - \l_fp_internal_tl 00 }
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \fp_exp_integer_tens:
+ \exp_after:wN \__fp_pack_twice_four:wNNNNNNNN
+ \exp_after:wN \__fp_pack_twice_four:wNNNNNNNN
+ \exp_after:wN \__fp_fixed_to_float_pack:ww
+ \exp_after:wN ;
+ \fi:
+ #1 #2 0000 0000 0000 0000 ;
+ }
+\cs_new:Npn \__fp_fixed_to_float_zero:w ; 0000 0000 0000 0000 ;
+ {
+ - \c_two * \c__fp_max_exponent_int ;
+ {0000} {0000} {0000} {0000} ;
+ }
+\cs_new:Npn \__fp_fixed_to_float_pack:ww #1 ; #2#3 ; ;
+ {
+ \if_int_compare:w #2 > \c_four
+ \exp_after:wN \__fp_fixed_to_float_round_up:wnnnnw
+ \fi:
+ ; #1 ;
+ }
+\cs_new:Npn \__fp_fixed_to_float_round_up:wnnnnw ; #1#2#3#4 ;
+ {
+ \exp_after:wN \__fp_basics_pack_high:NNNNNw
+ \int_use:N \__int_eval:w 1 #1#2
+ \exp_after:wN \__fp_basics_pack_low:NNNNNw
+ \int_use:N \__int_eval:w 1 #3#4 + \c_one ;
+ }
+\cs_new:Npn \__fp_fixed_inv_to_float:wN #1#2; #3
+ {
+ - \__int_eval:w
+ \if_int_compare:w #1 < \c_one_thousand
+ \__fp_fixed_dtf_zeros:wNnnnnnn
\fi:
- \else:
- \fp_exp_integer_const:n { \l_fp_internal_tl 00 }
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \fp_exp_integer_tens:
+ \__fp_fixed_dtf_no_zero:Nwn + {#1} #2 \s__fp
+ \__fp_fixed_dtf_approx:n
+ {10000} {0000} {0000} {0000} {0000} {0000} ;
+ }
+\cs_new:Npn \__fp_fixed_div_to_float:ww #1#2; #3#4;
+ {
+ \if_int_compare:w #1 < \c_one_thousand
+ \__fp_fixed_dtf_zeros:wNnnnnnn
+ \fi:
+ \__fp_fixed_dtf_no_zero:Nwn - {#1} #2 \s__fp
+ {
+ \if_int_compare:w #3 < \c_one_thousand
+ \__fp_fixed_dtf_zeros:wNnnnnnn
\fi:
+ \__fp_fixed_dtf_no_zero:Nwn + {#3} #4 \s__fp
+ \__fp_fixed_dtf_approx:n
+ }
+ }
+\cs_new:Npn \__fp_fixed_dtf_no_zero:Nwn #1#2 \s__fp #3 { #3 #2; }
+\cs_new:Npn \__fp_fixed_dtf_zeros:wNnnnnnn
+ \fi: \__fp_fixed_dtf_no_zero:Nwn #1#2#3#4#5#6#7
+ {
\fi:
+ #1 \c_minus_one
+ \exp_after:wN \use_i_ii:nnn
+ \exp_after:wN \__fp_fixed_dtf_zeros:NN
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w 10 0000 + #2 \__int_eval_end: #3#4#5#6#7
+ ; 1 ;
}
-\cs_new_protected_nopar:Npn \fp_exp_integer_tens:
+\cs_new:Npn \__fp_fixed_dtf_zeros:NN #1#2
{
- \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
- \if_int_compare:w \l_fp_input_a_integer_int > \c_nine
- \tl_set:Nx \l_fp_internal_tl
- {
- \exp_after:wN \use_i:nn
- \int_use:N \l_fp_input_a_integer_int
- }
- \l_fp_input_a_integer_int
- \int_eval:w
- \l_fp_input_a_integer_int - \l_fp_internal_tl 0
- \int_eval_end:
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- \fp_exp_integer_const:n { \l_fp_internal_tl 0 }
- \else:
- \fp_exp_integer_const:n { - \l_fp_internal_tl 0 }
- \fi:
- \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:
+ \if_meaning:w 0 #2
+ #1 \c_one
+ \else:
+ \__fp_fixed_dtf_zeros_end:wNww #2
\fi:
- \fp_exp_integer_units:
+ \__fp_fixed_dtf_zeros:NN #1
}
-\cs_new_protected_nopar:Npn \fp_exp_integer_units:
+\cs_new:Npn \__fp_fixed_dtf_zeros_end:wNww
+ #1 \fi: \__fp_fixed_dtf_zeros:NN #2 #3; #4 \s__fp
{
- \if_int_compare:w \l_fp_input_a_integer_int > \c_zero
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- \fp_exp_integer_const:n { \int_use:N \l_fp_input_a_integer_int }
- \else:
- \fp_exp_integer_const:n
- { - \int_use:N \l_fp_input_a_integer_int }
- \fi:
- \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:
\fi:
- \fp_exp_decimal:
+ \if_meaning:w ; #1
+ #2 \c_two * \c__fp_max_exponent_int
+ \use_i_ii:nnn
+ \fi:
+ \__fp_fixed_dtf_zeros_ii:ww
+ #1#3 0000 0000 0000 0000 0000 0000 ;
+ }
+\cs_new:Npn \__fp_fixed_dtf_zeros_ii:ww
+ {
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_fixed_dtf_zeros_iii:ww
+ ;
+ }
+\cs_new:Npn \__fp_fixed_dtf_zeros_iii:ww #1; #2; #3 { #3 #1; }
+\cs_new:Npn \__fp_fixed_dtf_approx:n #1
+ {
+ \exp_after:wN \__fp_fixed_dtf_approx_ii:wnn
+ \int_use:N \__int_eval:w 10 0000 0000 / ( #1 + \c_one ) ;
+ {#1}
+ }
+\cs_new:Npn \__fp_fixed_dtf_approx_ii:wnn #1; #2#3
+ {
+ \exp_after:wN \__fp_fixed_dtf_approx_iii:NNNNNw
+ \int_use:N \__int_eval:w 10 0000 0000 - 1750
+ + #1000 + (10 0000 0000/#2-#1) * (1000-#3/10) ;
+ {#2}{#3}
}
-\cs_new_protected:Npn \fp_exp_integer_const:n #1
+\cs_new:Npn \__fp_fixed_dtf_approx_iii:NNNNNw 1#1#2#3#4#5#6; #7; #8;
{
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_exp_integer_const:nnnn
- \cs:w c_fp_exp_ #1 _tl \cs_end:
+ + \c_four % because of the line below "dtf_epsilon" here.
+ \__fp_fixed_mul:wwn {000#1}{#2#3#4#5}{#6}{0000}{0000}{0000} ; #7;
+ \__fp_fixed_dtf_epsilon:wN
+ \__fp_fixed_mul:wwn {000#1}{#2#3#4#5}{#6}{0000}{0000}{0000} ;
+ \__fp_fixed_mul:wwn #8;
+ \__fp_fixed_to_float:wN ?
}
-\cs_new_protected:Npn \fp_exp_integer_const:nnnn #1#2#3#4
+\cs_new:Npn \__fp_fixed_dtf_epsilon:wN #1#2#3#4#5#6;
{
- \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:
+ \exp_after:wN \__fp_fixed_dtf_epsilon_ii:NNNNNww
+ \int_use:N \__int_eval:w 1 9999 9998 - #3#4 +
+ \exp_after:wN \__fp_fixed_dtf_epsilon_pack:NNNNNw
+ \int_use:N \__int_eval:w 2 0000 0000 - #5#6 ; {0000} ;
}
-\cs_new_protected_nopar:Npn \fp_exp_decimal:
+\cs_new:Npn \__fp_fixed_dtf_epsilon_pack:NNNNNw #1#2#3#4#5#6;
+ { #1 ; {#2#3#4#5} {#6} }
+\cs_new:Npn \__fp_fixed_dtf_epsilon_ii:NNNNNww #1#2#3#4#5#6; #7;
{
- \if_int_compare:w \l_fp_input_a_decimal_int > \c_zero
- \if_int_compare:w \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
+ \__fp_fixed_mul:wwn %^^A todo: optimize to use \__fp_mul_mantissa.
+ {0000} {#2#3#4#5} {#6} #7 ;
+ {0000} {#2#3#4#5} {#6} #7 ;
+ \__fp_fixed_add_one:wN
+ \__fp_fixed_mul:wwn {10000} {#2#3#4#5} {#6} #7 ;
+ }
+%% File: l3fp-expo.dtx Copyright (C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\tl_const:Nn \c__fp_ln_i_fixed_tl { {0000}{0000}{0000}{0000}{0000}{0000} }
+\tl_const:Nn \c__fp_ln_ii_fixed_tl { {6931}{4718}{0559}{9453}{0941}{7232} }
+\tl_const:Nn \c__fp_ln_iii_fixed_tl {{10986}{1228}{8668}{1096}{9139}{5245} }
+\tl_const:Nn \c__fp_ln_iv_fixed_tl {{13862}{9436}{1119}{8906}{1883}{4464} }
+ % \tl_const:Nn \c__fp_ln_v_fixed_tl {{16094}{3791}{2434}{1003}{7460}{0759} }
+\tl_const:Nn \c__fp_ln_vi_fixed_tl {{17917}{5946}{9228}{0550}{0081}{2477} }
+\tl_const:Nn \c__fp_ln_vii_fixed_tl {{19459}{1014}{9055}{3133}{0510}{5353} }
+\tl_const:Nn \c__fp_ln_viii_fixed_tl{{20794}{4154}{1679}{8359}{2825}{1696} }
+\tl_const:Nn \c__fp_ln_ix_fixed_tl {{21972}{2457}{7336}{2193}{8279}{0490} }
+\tl_const:Nn \c__fp_ln_x_fixed_tl {{23025}{8509}{2994}{0456}{8401}{7991} }
+ %\tl_const:Nn \c__fp_ln_ten_fixed_tl {{23025}{8509}{2994}{0456}{8401}{7991} }
+\cs_new:Npn \__fp_ln:w \s__fp \__fp_chk:w #1 #2
+ {
+ \if_meaning:w 0 #1
+ \__fp_case_use:nw
+ { \__fp_division_by_zero:Nnw \c_minus_inf_fp { ln } }
+ \fi:
+ \if_meaning:w 2 #2
+ \__fp_case_use:nw
+ { \__fp_invalid_operation:Nnw \c_nan_fp { ln } }
+ \fi:
+ \if_meaning:w 1 #1 \else:
+ \__fp_case_return_same_o:w
+ \fi:
+ \__fp_ln_npos:w \s__fp \__fp_chk:w #1#2
+ }
+\cs_new:Npn \__fp_ln_npos:w \s__fp \__fp_chk:w 10#1#2#3;
+ { %^^A todo: ln(1) should be "exact zero", not "underflow"
+ \exp_after:wN \__fp_sanitize:Nw
+ \__int_value:w % for the overall sign
+ \if_int_compare:w #1 < \c_one
+ 2
\else:
- \l_fp_exp_integer_int \c_zero
- \if_int_compare:w \l_fp_exp_extended_int = \c_zero
- \l_fp_exp_decimal_int
- \int_eval:w
- \c_one_thousand_million - \l_fp_input_a_decimal_int
- \int_eval_end:
- \l_fp_exp_extended_int \c_zero
+ 0
+ \fi:
+ \exp_after:wN \exp_stop_f:
+ \int_use:N \__int_eval:w % for the exponent
+ \__fp_ln_significand:NNNNnnnN #2#3
+ \__fp_ln_exponent:wn {#1}
+ }
+\cs_new:Npn \__fp_ln_significand:NNNNnnnN #1#2#3#4
+ {
+ \exp_after:wN \__fp_ln_x_ii:wnnnn
+ \__int_value:w
+ \if_case:w #1 \exp_stop_f:
+ \or:
+ \if_int_compare:w #2 < \c_four
+ \__int_eval:w \c_ten - #2
\else:
- \l_fp_exp_decimal_int
- \int_eval:w
- 999999999 - \l_fp_input_a_decimal_int
- \scan_stop:
- \l_fp_exp_extended_int
- \int_eval:w
- \c_one_thousand_million - \l_fp_input_a_extended_int
- \int_eval_end:
+ 6
\fi:
+ \or: 4
+ \or: 3
+ \or: 2
+ \or: 2
+ \or: 2
+ \else: 1
\fi:
- \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
- \fi:
- \if_int_compare:w \l_fp_output_extended_int < \c_five_hundred_million
- \else:
- \tex_advance:D \l_fp_output_decimal_int \c_one
- \if_int_compare:w \l_fp_output_decimal_int < \c_one_thousand_million
- \else:
- \l_fp_output_decimal_int \c_zero
- \tex_advance:D \l_fp_output_integer_int \c_one
- \fi:
- \fi:
- \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 }
+ ; { #1 #2 #3 #4 }
+ }
+\cs_new:Npn \__fp_ln_x_ii:wnnnn #1; #2#3#4#5
+ {
+ \exp_after:wN \__fp_ln_div_after:Nw
+ \cs:w c__fp_ln_ \tex_romannumeral:D #1 _fixed_tl \exp_after:wN \cs_end:
+ \__int_value:w
+ \exp_after:wN \__fp_ln_x_iv:nnnnnnnn
+ \tex_romannumeral:D -`0
+ \exp_after:wN \__fp_ln_x_iii_var:NNNNNw
+ \int_use:N \__int_eval:w 9999 9999 + #1*#2#3 +
+ \exp_after:wN \__fp_ln_x_iii:NNNNNw
+ \int_use:N \__int_eval:w 1 0000 0000 + #1*#4#5 ;
+ {20000} {0000} {0000} {0000}
+ } %^^A todo: reoptimize (a generalization attempt failed).
+\cs_new:Npn \__fp_ln_x_iii:NNNNNw #1 #2#3#4#5 #6; { #1; {#2#3#4#5} {#6} }
+\cs_new:Npn \__fp_ln_x_iii_var:NNNNNw #1 #2#3#4#5 #6; { {#1#2#3#4#5} {#6} }
+\cs_new:Npn \__fp_ln_x_iv:nnnnnnnn #1#2#3#4 #5#6#7#8
+ {
+ \exp_after:wN \__fp_ln_div_i:w
+ \int_use:N \__int_eval:w #1 + \c_one ;
+ #5 #6 ; {#7} {#8}
+ {#1} {#2} {#3} {#4}
+ }
+\cs_new:Npn \__fp_ln_div_i:w #1;
+ {
+ \exp_after:wN \__fp_ln_div_ii:www
+ \__int_value:w #1 \exp_after:wN ;
+ \__int_value:w
+ \exp_after:wN \__fp_div_mantissa_calc:Nwwnnnnnn
+ \int_use:N \__int_eval:w 999999 + 2 0000 0000 / #1 ; % Q1
+ }
+\cs_set_protected:Npn \__fp_tmp:w #1#2
+ {
+ \cs_new:Npn #1 ##1; ##2; ##3; % y; Q1; B1B2; <- for k=1
{
- +
- \int_use:N \l_fp_output_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_output_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_output_exponent_int
+ \exp_after:wN \__fp_div_mantissa_pack:NNN
+ \int_use:N \__int_eval:w ##2
+ \exp_after:wN #2
+ \__int_value:w ##1 \exp_after:wN ;
+ \__int_value:w
+ \exp_after:wN \__fp_div_mantissa_calc:Nwwnnnnnn
+ \int_use:N \__int_eval:w 999999 + ##3 / ##1 ; % Q2
+ ##3 ;
}
}
-\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
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_b_decimal_int + \l_fp_input_b_extended_int
- > \c_zero
- \if_int_compare:w \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
- \if_int_compare:w \l_fp_exp_extended_int < \c_one_thousand_million
+\__fp_tmp:w \__fp_ln_div_ii:www \__fp_ln_div_iii:www
+\__fp_tmp:w \__fp_ln_div_iii:www \__fp_ln_div_iv:www
+\__fp_tmp:w \__fp_ln_div_iv:www \__fp_ln_div_v:www
+\__fp_tmp:w \__fp_ln_div_v:www \__fp_ln_div_vi:www
+\cs_new:Npn \__fp_ln_div_vi:www #1; #2; #3;#4#5 #6#7#8#9 %y;Q5;F1F2;F3F4x1x2x3x4
+ {
+ \exp_after:wN \__fp_div_mantissa_pack:NNN
+ \int_use:N \__int_eval:w #2
+ \exp_after:wN \__fp_div_mantissa_pack:NNN
+ \int_use:N \__int_eval:w 1000000 + #3 / #1 ; % Q6
+ }
+\cs_new:Npn \__fp_ln_div_after:Nw #1#2;
+ {
+ \if_meaning:w 0 #2
+ \exp_after:wN \__fp_ln_t_small:Nw
+ \else:
+ \exp_after:wN \__fp_ln_t_large:NNw
+ \exp_after:wN -
+ \fi:
+ #1
+ }
+\cs_new:Npn \__fp_ln_t_small:Nw #1 #2; #3; #4; #5; #6; #7;
+ {
+ \exp_after:wN \__fp_ln_t_large:NNw
+ \exp_after:wN + % <sign>
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w 9999 - #2 \exp_after:wN ;
+ \int_use:N \__int_eval:w 9999 - #3 \exp_after:wN ;
+ \int_use:N \__int_eval:w 9999 - #4 \exp_after:wN ;
+ \int_use:N \__int_eval:w 9999 - #5 \exp_after:wN ;
+ \int_use:N \__int_eval:w 9999 - #6 \exp_after:wN ;
+ \int_use:N \__int_eval:w 1 0000 - #7 ;
+ }
+\cs_new:Npn \__fp_ln_t_large:NNw #1 #2 #3; #4; #5; #6; #7; #8;
+ {
+ \exp_after:wN \__fp_ln_square_t_after:w
+ \int_use:N \__int_eval:w 9999 0000 + #3*#3
+ \exp_after:wN \__fp_ln_square_t_pack:NNNNNw
+ \int_use:N \__int_eval:w 9999 0000 + 2*#3*#4
+ \exp_after:wN \__fp_ln_square_t_pack:NNNNNw
+ \int_use:N \__int_eval:w 9999 0000 + 2*#3*#5 + #4*#4
+ \exp_after:wN \__fp_ln_square_t_pack:NNNNNw
+ \int_use:N \__int_eval:w 9999 0000 + 2*#3*#6 + 2*#4*#5
+ \exp_after:wN \__fp_ln_square_t_pack:NNNNNw
+ \int_use:N \__int_eval:w 1 0000 0000 + 2*#3*#7 + 2*#4*#6 + #5*#5
+ + (2*#3*#8 + 2*#4*#7 + 2*#5*#6) / 1 0000
+ % ; ; ;
+ \exp_after:wN \__fp_ln_twice_t_after:w
+ \int_use:N \__int_eval:w -1 + 2*#3
+ \exp_after:wN \__fp_ln_twice_t_pack:Nw
+ \int_use:N \__int_eval:w 9999 + 2*#4
+ \exp_after:wN \__fp_ln_twice_t_pack:Nw
+ \int_use:N \__int_eval:w 9999 + 2*#5
+ \exp_after:wN \__fp_ln_twice_t_pack:Nw
+ \int_use:N \__int_eval:w 9999 + 2*#6
+ \exp_after:wN \__fp_ln_twice_t_pack:Nw
+ \int_use:N \__int_eval:w 9999 + 2*#7
+ \exp_after:wN \__fp_ln_twice_t_pack:Nw
+ \int_use:N \__int_eval:w 10000 + 2*#8 ; ;
+ { \__fp_ln_c:NwNw #1 }
+ #2
+ }
+\cs_new:Npn \__fp_ln_twice_t_pack:Nw #1 #2; { + #1 ; {#2} }
+\cs_new:Npn \__fp_ln_twice_t_after:w #1; { ;;; {#1} }
+\cs_new:Npn \__fp_ln_square_t_pack:NNNNNw #1 #2#3#4#5 #6;
+ { + #1#2#3#4#5 ; {#6} }
+\cs_new:Npn \__fp_ln_square_t_after:w 1 0 #1#2#3 #4;
+ { \__fp_ln_Taylor:wwNw {0#1#2#3} {#4} }
+\cs_new:Npn \__fp_ln_Taylor:wwNw
+ { \__fp_ln_Taylor_loop:www 21 ; {0000}{0000}{0000}{0000}{0000}{0000} ; }
+\cs_new:Npn \__fp_ln_Taylor_loop:www #1; #2; #3;
+ {
+ \if_int_compare:w #1 = \c_one
+ \__fp_ln_Taylor_break:w
+ \fi:
+ \exp_after:wN \__fp_fixed_div_int:wwN \c__fp_one_fixed_tl ; #1;
+ \__fp_fixed_add:wwN #2;
+ \__fp_fixed_mul:wwn #3;
+ {
+ \exp_after:wN \__fp_ln_Taylor_loop:www
+ \int_use:N \__int_eval:w #1 - \c_two ;
+ }
+ #3;
+ }
+\cs_new:Npn \__fp_ln_Taylor_break:w \fi: #1 \__fp_fixed_add:wwN #2#3; #4 ;;
+ {
+ \fi:
+ \exp_after:wN \__fp_fixed_mul:wwn
+ \exp_after:wN { \int_use:N \__int_eval:w 10000 + #2 } #3;
+ }
+\cs_new:Npn \__fp_ln_c:NwNw #1 #2; #3
+ {
+ \if_meaning:w + #1
+ \exp_after:wN \exp_after:wN \exp_after:wN \__fp_fixed_sub:wwN
+ \else:
+ \exp_after:wN \exp_after:wN \exp_after:wN \__fp_fixed_add:wwN
+ \fi:
+ #3 ; #2 ;
+ }
+\cs_new:Npn \__fp_ln_exponent:wn #1; #2
+ {
+ \if_case:w #2 \exp_stop_f:
+ \c_zero \__fp_case_return:nw { \__fp_fixed_to_float:Nw 2 }
+ \or:
+ \exp_after:wN \__fp_ln_exponent_one:ww \__int_value:w
+ \else:
+ \if_int_compare:w #2 > \c_zero
+ \exp_after:wN \__fp_ln_exponent_small:NNww
+ \exp_after:wN 0
+ \exp_after:wN \__fp_fixed_sub:wwN \__int_value:w
\else:
- \tex_advance:D \l_fp_exp_decimal_int \c_one
- \tex_advance:D \l_fp_exp_extended_int
- -\c_one_thousand_million
- \fi:
- \if_int_compare:w \l_fp_exp_decimal_int < \c_one_thousand_million
- \else:
- \tex_advance:D \l_fp_exp_integer_int \c_one
- \tex_advance:D \l_fp_exp_decimal_int
- -\c_one_thousand_million
- \fi:
+ \exp_after:wN \__fp_ln_exponent_small:NNww
+ \exp_after:wN 2
+ \exp_after:wN \__fp_fixed_add:wwN \__int_value:w -
+ \fi:
+ \fi:
+ #2; #1;
+ }
+\cs_new:Npn \__fp_ln_exponent_one:ww 1; #1;
+ {
+ \c_zero
+ \exp_after:wN \__fp_fixed_sub:wwN \c__fp_ln_x_fixed_tl ; #1;
+ \__fp_fixed_to_float:wN 0
+ }
+\cs_new:Npn \__fp_ln_exponent_small:NNww #1#2#3; #4#5#6#7#8#9;
+ {
+ \c_four
+ \exp_after:wN \__fp_fixed_mul:wwn
+ \c__fp_ln_x_fixed_tl ;
+ {#3}{0000}{0000}{0000}{0000}{0000} ;
+ #2
+ {0000}{#4}{#5}{#6}{#7}{#8};
+ \__fp_fixed_to_float:wN #1
+ }
+\cs_new:Npn \__fp_exp:w \s__fp \__fp_chk:w #1#2
+ {
+ \if_case:w #1 \exp_stop_f:
+ \__fp_case_return_o:Nw \c_one_fp
+ \or:
+ \exp_after:wN \__fp_exp_normal:w
+ \or:
+ \if_meaning:w 0 #2
+ \exp_after:wN \__fp_case_return_o:Nw
+ \exp_after:wN \c_inf_fp
\else:
- \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
- \if_int_compare:w \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
- \fi:
- \if_int_compare:w \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
- \fi:
+ \exp_after:wN \__fp_case_return_o:Nw
+ \exp_after:wN \c_zero_fp
\fi:
- \exp_after:wN \fp_exp_Taylor:
- \fi:
- }
-\cs_new_protected: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_const:cn { c_fp_ln_10_1_tl } { { 2 } { 302585092 } { 994045684 } { 0 } }
-\tl_const:cn { c_fp_ln_10_2_tl } { { 4 } { 605170185 } { 988091368 } { 0 } }
-\tl_const:cn { c_fp_ln_10_3_tl } { { 6 } { 907755278 } { 982137052 } { 0 } }
-\tl_const:cn { c_fp_ln_10_4_tl } { { 9 } { 210340371 } { 976182736 } { 0 } }
-\tl_const:cn { c_fp_ln_10_5_tl } { { 1 } { 151292546 } { 497022842 } { 1 } }
-\tl_const:cn { c_fp_ln_10_6_tl } { { 1 } { 381551055 } { 796427410 } { 1 } }
-\tl_const:cn { c_fp_ln_10_7_tl } { { 1 } { 611809565 } { 095831979 } { 1 } }
-\tl_const:cn { c_fp_ln_10_8_tl } { { 1 } { 842068074 } { 395226547 } { 1 } }
-\tl_const:cn { c_fp_ln_10_9_tl } { { 2 } { 072326583 } { 694641116 } { 1 } }
-\tl_const:cn { c_fp_ln_2_1_tl } { { 0 } { 693147180 } { 559945309 } { 0 } }
-\tl_const:cn { c_fp_ln_2_2_tl } { { 1 } { 386294361 } { 119890618 } { 0 } }
-\tl_const: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: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
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int
- > \c_zero
- \exp_after:wN \exp_after:wN \exp_after:wN \fp_ln_aux:
- \else:
- \cs_set_protected:Npx \fp_tmp:w ##1##2
- {
- \group_end:
- ##1 \exp_not:N ##2 { \c_zero_fp }
- }
- \exp_after:wN \exp_after:wN \exp_after:wN \fp_ln_error_msg:
- \fi:
+ \or:
+ \__fp_case_return_same_o:w
+ \fi:
+ \s__fp \__fp_chk:w #1#2
+ }
+\cs_new:Npn \__fp_exp_normal:w \s__fp \__fp_chk:w 1#1
+ {
+ \if_meaning:w 0 #1
+ \__fp_exp_pos:NNwnw + \__fp_fixed_to_float:wN
+ \else:
+ \__fp_exp_pos:NNwnw - \__fp_fixed_inv_to_float:wN
+ \fi:
+ }
+\cs_new:Npn \__fp_exp_pos:NNwnw #1#2#3 \fi: #4#5;
+ {
+ \fi:
+ \exp_after:wN \__fp_sanitize:Nw
+ \exp_after:wN 0
+ \__int_value:w #1 \__int_eval:w
+ \if_int_compare:w #4 < - \c_eight
+ \c_one
+ \exp_after:wN \__fp_add_big_i:wNww
+ \int_use:N \__int_eval:w \c_one - #4 ;
+ 0 {1000}{0000}{0000}{0000} ; #5;
+ \tex_romannumeral:D
\else:
- \cs_set_protected:Npx \fp_tmp:w ##1##2
+ \if_int_compare:w #4 > \c_five % cf \c__fp_max_exponent_int
+ \exp_after:wN \__fp_exp_overflow:
+ \tex_romannumeral:D
+ \else:
+ \if_int_compare:w #4 < \c_zero
+ \exp_after:wN \use_i:nn
+ \else:
+ \exp_after:wN \use_ii:nn
+ \fi:
+ {
+ \c_zero
+ \__fp_decimate:nNnnnn { - #4 }
+ \__fp_exp_Taylor:Nnnwn
+ }
{
- \group_end:
- ##1 \exp_not:N ##2 { \c_zero_fp }
+ \__fp_decimate:nNnnnn { \c_sixteen - #4 }
+ \__fp_exp_pos_large:NnnNwn
}
- \exp_after:wN \fp_ln_error_msg:
+ #5
+ {#4}
+ #2 0
+ \tex_romannumeral:D
+ \fi:
\fi:
- \fp_tmp:w #1 #2
+ \exp_after:wN \c_zero
}
-\cs_new_protected_nopar:Npn \fp_ln_aux:
+\cs_new:Npn \__fp_exp_overflow:
+ { + \c_two * \c__fp_max_exponent_int ; {1000} {0000} {0000} {0000} ; }
+\cs_new:Npn \__fp_exp_Taylor:Nnnwn #1#2#3 #4; #5
{
- \tl_set:Nx \l_fp_arg_tl
- {
- +
- \int_use:N \l_fp_input_a_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_input_a_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_input_a_exponent_int
- }
- \if_cs_exist:w c_fp_ln ( \l_fp_arg_tl ) _fp \cs_end:
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_exp_Taylor_ii:ww
+ ; #2#3#4 0000 0000 ;
+ }
+\cs_new:Npn \__fp_exp_Taylor_ii:ww #1; #2;
+ { \__fp_exp_Taylor_loop:www 10 ; #1 ; #1 ; \s__stop }
+\cs_new:Npn \__fp_exp_Taylor_loop:www #1; #2; #3;
+ {
+ \if_int_compare:w #1 = \c_one
+ \exp_after:wN \__fp_exp_Taylor_break:Nww
+ \fi:
+ \__fp_fixed_div_int:wwN #3 ; #1 ;
+ \__fp_fixed_add_one:wN
+ \__fp_fixed_mul:wwn #2 ;
+ {
+ \exp_after:wN \__fp_exp_Taylor_loop:www
+ \int_use:N \__int_eval:w #1 - 1 ;
+ #2 ;
+ }
+ }
+\cs_new:Npn \__fp_exp_Taylor_break:Nww #1 #2; #3 \s__stop
+ { \__fp_fixed_add_one:wN #2 ; }
+\cs_new:Npn \__fp_exp_pos_large:NnnNwn #1#2#3 #4#5; #6
+ {
+ \exp_after:wN \exp_after:wN
+ \cs:w __fp_exp_large_\tex_romannumeral:D #6:wN \exp_after:wN \cs_end:
+ \exp_after:wN \c__fp_one_fixed_tl
+ \exp_after:wN ;
+ \__int_value:w #3 #4 \exp_stop_f:
+ #5 00000 ;
+ }
+\cs_new:Npn \__fp_exp_large:w #1 \or: #2 \fi:
+ { \fi: \__fp_fixed_mul:wwn #1; }
+\cs_new:Npn \__fp_exp_large_v:wN #1; #2
+ {
+ \if_case:w #2 ~ \exp_after:wN \__fp_fixed_continue:wn \or:
+ + 4343 \__fp_exp_large:w {8806}{8182}{2566}{2921}{5872}{6150} \or:
+ + 8686 \__fp_exp_large:w {7756}{0047}{2598}{6861}{0458}{3204} \or:
+ + 13029 \__fp_exp_large:w {6830}{5723}{7791}{4884}{1932}{7351} \or:
+ + 17372 \__fp_exp_large:w {6015}{5609}{3095}{3052}{3494}{7574} \or:
+ + 21715 \__fp_exp_large:w {5297}{7951}{6443}{0315}{3251}{3576} \or:
+ + 26058 \__fp_exp_large:w {4665}{6719}{0099}{3379}{5527}{2929} \or:
+ + 30401 \__fp_exp_large:w {4108}{9724}{3326}{3186}{5271}{5665} \or:
+ + 34744 \__fp_exp_large:w {3618}{6973}{3140}{0875}{3856}{4102} \or:
+ + 39087 \__fp_exp_large:w {3186}{9209}{6113}{3900}{6705}{9685} \or:
+ \fi:
+ #1;
+ \__fp_exp_large_iv:wN
+ }
+\cs_new:Npn \__fp_exp_large_iv:wN #1; #2
+ {
+ \if_case:w #2 ~ \exp_after:wN \__fp_fixed_continue:wn \or:
+ + 435 \__fp_exp_large:w {1970}{0711}{1401}{7046}{9938}{8888} \or:
+ + 869 \__fp_exp_large:w {3881}{1801}{9428}{4368}{5764}{8232} \or:
+ + 1303 \__fp_exp_large:w {7646}{2009}{8905}{4704}{8893}{1073} \or:
+ + 1738 \__fp_exp_large:w {1506}{3559}{7005}{0524}{9009}{7592} \or:
+ + 2172 \__fp_exp_large:w {2967}{6283}{8402}{3667}{0689}{6630} \or:
+ + 2606 \__fp_exp_large:w {5846}{4389}{5650}{2114}{7278}{5046} \or:
+ + 3041 \__fp_exp_large:w {1151}{7900}{5080}{6878}{2914}{4154} \or:
+ + 3475 \__fp_exp_large:w {2269}{1083}{0850}{6857}{8724}{4002} \or:
+ + 3909 \__fp_exp_large:w {4470}{3047}{3316}{5442}{6408}{6591} \or:
+ \fi:
+ #1;
+ \__fp_exp_large_iii:wN
+ }
+\cs_new:Npn \__fp_exp_large_iii:wN #1; #2
+ {
+ \if_case:w #2 ~ \exp_after:wN \__fp_fixed_continue:wn \or:
+ + 44 \__fp_exp_large:w {2688}{1171}{4181}{6135}{4484}{1263} \or:
+ + 87 \__fp_exp_large:w {7225}{9737}{6812}{5749}{2581}{7748} \or:
+ + 131 \__fp_exp_large:w {1942}{4263}{9524}{1255}{9365}{8421} \or:
+ + 174 \__fp_exp_large:w {5221}{4696}{8976}{4143}{9505}{8876} \or:
+ + 218 \__fp_exp_large:w {1403}{5922}{1785}{2837}{4107}{3977} \or:
+ + 261 \__fp_exp_large:w {3773}{0203}{0092}{9939}{8234}{0143} \or:
+ + 305 \__fp_exp_large:w {1014}{2320}{5473}{5004}{5094}{5533} \or:
+ + 348 \__fp_exp_large:w {2726}{3745}{7211}{2566}{5673}{6478} \or:
+ + 391 \__fp_exp_large:w {7328}{8142}{2230}{7421}{7051}{8866} \or:
+ \fi:
+ #1;
+ \__fp_exp_large_ii:wN
+ }
+\cs_new:Npn \__fp_exp_large_ii:wN #1; #2
+ {
+ \if_case:w #2 ~ \exp_after:wN \__fp_fixed_continue:wn \or:
+ + 5 \__fp_exp_large:w {2202}{6465}{7948}{0671}{6516}{9579} \or:
+ + 9 \__fp_exp_large:w {4851}{6519}{5409}{7902}{7796}{9107} \or:
+ + 14 \__fp_exp_large:w {1068}{6474}{5815}{2446}{2146}{9905} \or:
+ + 18 \__fp_exp_large:w {2353}{8526}{6837}{0199}{8540}{7900} \or:
+ + 22 \__fp_exp_large:w {5184}{7055}{2858}{7072}{4640}{8745} \or:
+ + 27 \__fp_exp_large:w {1142}{0073}{8981}{5684}{2836}{6296} \or:
+ + 31 \__fp_exp_large:w {2515}{4386}{7091}{9167}{0062}{6578} \or:
+ + 35 \__fp_exp_large:w {5540}{6223}{8439}{3510}{0525}{7117} \or:
+ + 40 \__fp_exp_large:w {1220}{4032}{9431}{7840}{8020}{0271} \or:
+ \fi:
+ #1;
+ \__fp_exp_large_i:wN
+ }
+\cs_new:Npn \__fp_exp_large_i:wN #1; #2
+ {
+ \if_case:w #2 ~ \exp_after:wN \__fp_fixed_continue:wn \or:
+ + 1 \__fp_exp_large:w {2718}{2818}{2845}{9045}{2353}{6029} \or:
+ + 1 \__fp_exp_large:w {7389}{0560}{9893}{0650}{2272}{3043} \or:
+ + 2 \__fp_exp_large:w {2008}{5536}{9231}{8766}{7740}{9285} \or:
+ + 2 \__fp_exp_large:w {5459}{8150}{0331}{4423}{9078}{1103} \or:
+ + 3 \__fp_exp_large:w {1484}{1315}{9102}{5766}{0342}{1116} \or:
+ + 3 \__fp_exp_large:w {4034}{2879}{3492}{7351}{2260}{8387} \or:
+ + 4 \__fp_exp_large:w {1096}{6331}{5842}{8458}{5992}{6372} \or:
+ + 4 \__fp_exp_large:w {2980}{9579}{8704}{1728}{2747}{4359} \or:
+ + 4 \__fp_exp_large:w {8103}{0839}{2757}{5384}{0077}{1000} \or:
+ \fi:
+ #1;
+ \__fp_exp_large_:wN
+ }
+\cs_new:Npn \__fp_exp_large_:wN #1; #2
+ {
+ \if_case:w #2 ~ \exp_after:wN \__fp_fixed_continue:wn \or:
+ + 1 \__fp_exp_large:w {1105}{1709}{1807}{5647}{6248}{1171} \or:
+ + 1 \__fp_exp_large:w {1221}{4027}{5816}{0169}{8339}{2107} \or:
+ + 1 \__fp_exp_large:w {1349}{8588}{0757}{6003}{1039}{8374} \or:
+ + 1 \__fp_exp_large:w {1491}{8246}{9764}{1270}{3178}{2485} \or:
+ + 1 \__fp_exp_large:w {1648}{7212}{7070}{0128}{1468}{4865} \or:
+ + 1 \__fp_exp_large:w {1822}{1188}{0039}{0508}{9748}{7537} \or:
+ + 1 \__fp_exp_large:w {2013}{7527}{0747}{0476}{5216}{2455} \or:
+ + 1 \__fp_exp_large:w {2225}{5409}{2849}{2467}{6045}{7954} \or:
+ + 1 \__fp_exp_large:w {2459}{6031}{1115}{6949}{6638}{0013} \or:
+ \fi:
+ #1;
+ \__fp_exp_large_after:wwn
+ }
+\cs_new:Npn \__fp_exp_large_after:wwn #1; #2;
+ {
+ \__fp_exp_Taylor:Nnnwn ? { } { } 0 #2; {}
+ \__fp_fixed_mul:wwn #1;
+ }
+\cs_new:cpn { __fp_ \iow_char:N \^ _o:ww }
+ \s__fp \__fp_chk:w #1#2#3; \s__fp \__fp_chk:w #4#5#6;
+ {
+ \if_meaning:w 0 #4
+ \__fp_case_return_o:Nw \c_one_fp
+ \fi:
+ \if_case:w #2 \exp_stop_f:
+ \exp_after:wN \use_i:nn
+ \or:
+ \__fp_case_return_o:Nw \c_nan_fp
\else:
- \exp_after:wN \fp_ln_exponent:
+ \exp_after:wN \__fp_pow_neg:www
+ \tex_romannumeral:D -`0 \exp_after:wN \use:nn
\fi:
- \cs_set_protected:Npx \fp_tmp:w ##1##2
- {
- \group_end:
- ##1 \exp_not:N ##2
- { \use:c { c_fp_ln ( \l_fp_arg_tl ) _fp } }
- }
+ {
+ \if_meaning:w 1 #1
+ \exp_after:wN \__fp_pow_normal:ww
+ \else:
+ \exp_after:wN \__fp_pow_zero_or_inf:ww
+ \fi:
+ \s__fp \__fp_chk:w #1#2#3;
+ }
+ { \s__fp \__fp_chk:w #4#5#6; \s__fp \__fp_chk:w #1#2#3; }
+ \s__fp \__fp_chk:w #4#5#6;
}
-\cs_new_protected_nopar:Npn \fp_ln_exponent:
+\cs_new:Npn \__fp_pow_zero_or_inf:ww \s__fp \__fp_chk:w #1#2; \s__fp \__fp_chk:w #3#4
{
- \fp_ln_internal:
- \if_int_compare:w \l_fp_output_extended_int < \c_five_hundred_million
+ \if_meaning:w 1 #4
+ \__fp_case_return_same_o:w
+ \fi:
+ \if_meaning:w #1 #4
+ \__fp_case_return_o:Nw \c_zero_fp
\else:
- \tex_advance:D \l_fp_output_decimal_int \c_one
- \if_int_compare:w \l_fp_output_decimal_int < \c_one_thousand_million
+ \__fp_case_return_o:Nw \c_inf_fp
+ \fi:
+ \s__fp \__fp_chk:w #3#4
+ }
+\cs_new:Npn \__fp_pow_normal:ww \s__fp \__fp_chk:w 1 #1#2#3; \s__fp \__fp_chk:w #4#5
+ {
+ \if_int_compare:w \pdftex_strcmp:D { #2 #3 }
+ { 1 {1000} {0000} {0000} {0000} } = \c_zero
+ \if_int_compare:w #4 #1 = 32 \exp_stop_f:
+ \exp_after:wN \__fp_case_return_ii_o:ww
+ \fi:
+ \__fp_case_return_o:Nww \c_one_fp
+ \fi:
+ \if_case:w #4 ~
+ \or:
+ \exp_after:wN \__fp_pow_npos:Nww
+ \exp_after:wN #5
+ \or:
+ \if_meaning:w 2 #5 \exp_after:wN \reverse_if:N \fi:
+ \if_int_compare:w #2 > \c_zero
+ \exp_after:wN \__fp_case_return_o:Nww
+ \exp_after:wN \c_inf_fp
\else:
- \l_fp_output_decimal_int \c_zero
- \tex_advance:D \l_fp_output_integer_int \c_one
+ \exp_after:wN \__fp_case_return_o:Nww
+ \exp_after:wN \c_zero_fp
\fi:
+ \or:
+ \__fp_case_return_ii_o:ww
\fi:
- \fp_standardise:NNNN
- \l_fp_output_sign_int
- \l_fp_output_integer_int
- \l_fp_output_decimal_int
- \l_fp_output_exponent_int
- \tl_const:cx { c_fp_ln ( \l_fp_arg_tl ) _fp }
- {
- \if_int_compare:w \l_fp_output_sign_int > \c_zero
- +
- \else:
- -
- \fi:
- \int_use:N \l_fp_output_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_output_decimal_int + \c_one_thousand_million
- \scan_stop:
- e
- \int_use:N \l_fp_output_exponent_int
- }
+ \s__fp \__fp_chk:w 1 #1 {#2} #3 ;
+ \s__fp \__fp_chk:w #4 #5
}
-\cs_new_protected_nopar:Npn \fp_ln_internal:
+\cs_new:Npn \__fp_pow_npos:Nww #1 \s__fp \__fp_chk:w 1#2#3
{
- \if_int_compare:w \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
+ \exp_after:wN \__fp_sanitize:Nw
+ \exp_after:wN 0
+ \__int_value:w
+ \if:w #1 \if_int_compare:w #3 > \c_zero 0 \else: 2 \fi:
+ \exp_after:wN \__fp_pow_npos_aux:Nnww
+ \exp_after:wN \__fp_fixed_to_float:wN
+ \else:
+ -
+ \exp_after:wN \__fp_pow_npos_aux:Nnww
+ \exp_after:wN \__fp_fixed_inv_to_float:wN
+ \fi:
+ {#3}
+ }
+\cs_new:Npn \__fp_pow_npos_aux:Nnww #1#2#3#4; \s__fp \__fp_chk:w 1#5#6#7;
+ {
+ \__int_eval:w
+ \__fp_ln_significand:NNNNnnnN #3#4
+ \__fp_pow_exponent:wnN {#2}
+ \__fp_fixed_mul:wwn #7 {0000}{0000} ;
+ \__fp_pow_B:wwN #6;
+ #1 0 % fixed_to_float:wN
+ }
+\cs_new:Npn \__fp_pow_exponent:wnN #1; #2
+ {
+ \if_int_compare:w #2 > \c_zero
+ \exp_after:wN \__fp_pow_exponent:Nwnnnnnn % n\log 10 - (-\log x)
+ \exp_after:wN +
\else:
- \l_fp_output_sign_int \c_one
+ \exp_after:wN \__fp_pow_exponent:Nwnnnnnn % -( |n|\log 10 + (-\log x) )
+ \exp_after:wN -
\fi:
- \if_int_compare:w \l_fp_input_a_exponent_int > \c_nine
- \exp_after:wN \fp_ln_exponent_tens:NN
- \int_use:N \l_fp_input_a_exponent_int
+ #2; #1;
+ }
+\cs_new:Npn \__fp_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 \__fp_fixed_mul_after:wwn
+ \int_use:N \__int_eval:w -5 0000
+ \exp_after:wN \__fp_fixed_mul_pack:NNNNNw
+ \int_use:N \__int_eval:w 4 9995 0000 #1#2*23025 - #1 #3
+ \exp_after:wN \__fp_fixed_mul_pack:NNNNNw
+ \int_use:N \__int_eval:w 4 9995 0000 #1 #2*8509 - #1 #4
+ \exp_after:wN \__fp_fixed_mul_pack:NNNNNw
+ \int_use:N \__int_eval:w 4 9995 0000 #1 #2*2994 - #1 #5
+ \exp_after:wN \__fp_fixed_mul_pack:NNNNNw
+ \int_use:N \__int_eval:w 4 9995 0000 #1 #2*0456 - #1 #6
+ \exp_after:wN \__fp_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 \__fp_pow_B:wwN #1#2#3#4#5#6; #7;
+ {
+ \if_int_compare:w #7 < \c_zero
+ \exp_after:wN \__fp_pow_C_neg:w \__int_value:w -
\else:
- \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
+ \if_int_compare:w #7 < 22 \exp_stop_f:
+ \exp_after:wN \__fp_pow_C_pos:w \__int_value:w
+ \else:
+ \exp_after:wN \__fp_pow_C_overflow:w \__int_value:w
+ \fi:
\fi:
- \fp_ln_exponent_units:
+ #7 \exp_after:wN ;
+ \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_protected:Npn \fp_ln_exponent_tens:NN #1 #2
+\cs_new:Npn \__fp_pow_C_overflow:w #1; #2;
{
- \l_fp_input_a_exponent_int #2 \scan_stop:
- \fp_ln_const:nn { 10 } { #1 }
- \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
+ + \c_two * \c__fp_max_exponent_int
+ \exp_after:wN \__fp_fixed_continue:wn \c__fp_one_fixed_tl ;
}
-\cs_new_protected_nopar:Npn \fp_ln_exponent_units:
+\cs_new:Npn \__fp_pow_C_neg:w #1 ; 1
{
- \if_int_compare:w \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
- \fi:
- \fp_ln_mantissa:
+ \exp_after:wN \exp_after:wN \exp_after:wN \__fp_pow_C_pack:w
+ \prg_replicate:nn {#1} {0}
}
-\cs_new_protected_nopar:Npn \fp_ln_normalise:
+\cs_new:Npn \__fp_pow_C_pos:w #1; 1
+ { \__fp_pow_C_pos_loop:wN #1; }
+\cs_new:Npn \__fp_pow_C_pos_loop:wN #1; #2
{
- \if_int_compare:w \l_fp_exp_exponent_int < \l_fp_output_exponent_int
- \tex_advance:D \l_fp_exp_decimal_int \c_one_thousand_million
- \exp_after:wN \use_i:nn \exp_after:wN
- \fp_ln_normalise_aux:NNNNNNNNN
- \int_use:N \l_fp_exp_decimal_int
- \exp_after:wN \fp_ln_normalise:
+ \if_meaning:w 0 #1
+ \exp_after:wN \__fp_pow_C_pack:w
+ \exp_after:wN #2
\else:
- \l_fp_output_exponent_int \l_fp_exp_exponent_int
+ \if_meaning:w 0 #2
+ \exp_after:wN \__fp_pow_C_pos_loop:wN \__int_value:w
+ \else:
+ \exp_after:wN \__fp_pow_C_overflow:w \__int_value:w
+ \fi:
+ \__int_eval:w #1 - \c_one \exp_after:wN ;
\fi:
}
-\cs_new_protected:Npn \fp_ln_normalise_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9
+\cs_new:Npn \__fp_pow_C_pack:w
+ { \exp_after:wN \__fp_exp_large_v:wN \c__fp_one_fixed_tl ; }
+\cs_new:Npn \__fp_pow_neg:www \s__fp \__fp_chk:w #1#2; #3; #4;
{
- \if_int_compare:w \l_fp_exp_integer_int = \c_zero
- \l_fp_exp_decimal_int #1#2#3#4#5#6#7#8 \scan_stop:
- \else:
- \tl_set:Nx \l_fp_internal_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_internal_tl \scan_stop:
+ \if_case:w \__fp_pow_neg_case:w #4 ;
+ \exp_after:wN \__fp_pow_neg_neg:w
+ \or:
+ \if_int_compare:w \__int_eval:w #1 / \c_two = \c_one
+ \__fp_invalid_operation:Nnww \c_nan_fp { ^ } #3; #4;
+ \tex_romannumeral:D -`0
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_use_none_until_s:w
+ \fi:
\fi:
- \tex_divide:D \l_fp_exp_extended_int \c_ten
- \tl_set:Nx \l_fp_internal_tl
- {
- #9
- \int_use:N \l_fp_exp_extended_int
- }
- \l_fp_exp_extended_int \l_fp_internal_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:
- \if_int_compare:w \l_fp_count_int > \c_zero
- \fp_ln_const:nn { 2 } { \int_use:N \l_fp_count_int }
- \fp_ln_normalise:
- \if_int_compare:w \l_fp_output_sign_int > \c_zero
- \exp_after:wN \fp_add:NNNNNNNNN
+ \__fp_exp_after_o:w
+ \s__fp \__fp_chk:w #1#2;
+ }
+\cs_new:Npn \__fp_pow_neg_neg:w \__fp_exp_after_o:w \s__fp \__fp_chk:w #1#2
+ {
+ \exp_after:wN \__fp_exp_after_o:w
+ \exp_after:wN \s__fp
+ \exp_after:wN \__fp_chk:w
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w \c_two - #2 \__int_eval_end:
+ }
+\cs_new:Npn \__fp_pow_neg_case:w \s__fp \__fp_chk:w #1#2#3;
+ {
+ \if_case:w #1 \exp_stop_f:
+ \c_minus_one
+ \or: \__fp_pow_neg_case_aux:nnnnn #3
+ \else: \c_one
+ \fi:
+ }
+\cs_new:Npn \__fp_pow_neg_case_aux:nnnnn #1#2#3#4#5
+ {
+ \if_int_compare:w #1 > \c_eight
+ \if_int_compare:w #1 > \c_sixteen
+ \c_minus_one
\else:
- \exp_after:wN \fp_sub:NNNNNNNNN
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_pow_neg_case_aux:NNNNNNNNw
+ \prg_replicate:nn { \c_sixteen - #1 } { 0 } #4#5 ;
\fi:
- \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
- \fi:
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int > \c_one
- \exp_after:wN \fp_ln_Taylor:
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_ln_mantissa_aux:
- {
- \if_int_compare:w \l_fp_input_a_integer_int > \c_one
- \tex_advance:D \l_fp_count_int \c_one
- \fp_ln_mantissa_divide_two:
- \exp_after:wN \fp_ln_mantissa_aux:
- \fi:
- }
-\cs_new_protected_nopar:Npn \fp_ln_mantissa_divide_two:
- {
- \if_int_odd:w \l_fp_input_a_decimal_int
- \tex_advance:D \l_fp_input_a_extended_int \c_one_thousand_million
- \fi:
- \if_int_odd:w \l_fp_input_a_integer_int
- \tex_advance:D \l_fp_input_a_decimal_int \c_one_thousand_million
- \fi:
- \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:Npn \fp_ln_const:nn #1#2
- {
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_exp_integer_const:nnnn
- \cs:w c_fp_ln_ #1 _ #2 _tl \cs_end:
- }
-\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_extended_int \c_zero
- \l_fp_input_a_exponent_int \l_fp_output_exponent_int
- \l_fp_output_decimal_int \c_zero %^^A Bug?
- \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:
- \l_fp_exp_integer_int \c_zero
- \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
- \if_int_compare:w \l_fp_exp_extended_int < \c_five_hundred_million
\else:
- \tex_advance:D \l_fp_exp_extended_int -\c_five_hundred_million
- \tex_advance:D \l_fp_exp_decimal_int \c_one
+ \if_int_compare:w #1 > \c_zero
+ \if_int_compare:w #4#5 = \c_zero
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_pow_neg_case_aux:NNNNNNNNw
+ \prg_replicate:nn { \c_eight - #1 } { 0 } #2#3 ;
+ \else:
+ \c_one
+ \fi:
+ \else:
+ \c_one
+ \fi:
\fi:
- \tex_advance:D \l_fp_exp_extended_int \l_fp_exp_extended_int
- \fp_ln_normalise:
- \if_int_compare:w \l_fp_output_sign_int > \c_zero
- \exp_after:wN \fp_add:NNNNNNNNN
+ }
+\cs_new:Npn \__fp_pow_neg_case_aux:NNNNNNNNw #1#2#3#4#5#6#7#8#9;
+ {
+ \if_int_compare:w 0 #9 = \c_zero
+ \if_int_odd:w #8 \exp_stop_f:
+ \c_zero
+ \else:
+ \c_minus_one
+ \fi:
\else:
- \exp_after:wN \fp_sub:NNNNNNNNN
+ \c_one
\fi:
- \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:
+%% File: l3fp-trig.dtx Copyright (C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\cs_new_nopar:Npx \__fp_one_over:w
{
- \if_int_compare:w \l_fp_output_exponent_int < \c_zero
- \tex_advance:D \l_fp_output_decimal_int \c_one_thousand_million
- \exp_after:wN \use_i:nn \exp_after:wN
- \fp_ln_fixed_aux:NNNNNNNNN
- \int_use:N \l_fp_output_decimal_int
- \exp_after:wN \fp_ln_fixed:
- \fi:
+ \exp_not:N \exp_after:wN
+ \exp_not:c { __fp_/_o:ww }
+ \exp_not:N \c_one_fp
}
-\cs_new_protected:Npn \fp_ln_fixed_aux:NNNNNNNNN #1#2#3#4#5#6#7#8#9
+\cs_new:Npn \__fp_sin:w \s__fp \__fp_chk:w #1#2
{
- \if_int_compare:w \l_fp_output_integer_int = \c_zero
- \l_fp_output_decimal_int #1#2#3#4#5#6#7#8 \scan_stop:
- \else:
- \tl_set:Nx \l_fp_internal_tl
+ \if_case:w #1 \exp_stop_f:
+ \__fp_case_return_same_o:w
+ \or:
+ \exp_after:wN \__fp_trig_exponent:NNNNwn
+ \exp_after:wN \__fp_sin_series:NNwww
+ \exp_after:wN ?
+ \exp_after:wN #2
+ \exp_after:wN \c_zero
+ \or:
+ \__fp_case_use:nw
+ { \__fp_invalid_operation:Nnw \c_nan_fp { sin } }
+ \else: \__fp_case_return_same_o:w
+ \fi:
+ \s__fp \__fp_chk:w #1#2
+ }
+\cs_new:Npn \__fp_cos:w \s__fp \__fp_chk:w #1#2
+ {
+ \if_case:w #1 \exp_stop_f:
+ \__fp_case_return_o:Nw \c_one_fp
+ \or:
+ \__fp_case_use:nw %^^A todo: is that faster than the exp_after route?
{
- \int_use:N \l_fp_output_integer_int
- #1#2#3#4#5#6#7#8
+ \__fp_trig_exponent:NNNNwn
+ \__fp_sin_series:NNwww
+ ?
+ 0
+ \c_two
}
- \l_fp_output_integer_int \c_zero
- \l_fp_output_decimal_int \l_fp_internal_tl \scan_stop:
+ \or:
+ \__fp_case_use:nw
+ { \__fp_invalid_operation:Nnw \c_nan_fp { cos } }
+ \else: \__fp_case_return_same_o:w
\fi:
- \tex_advance:D \l_fp_output_exponent_int \c_one
+ \s__fp \__fp_chk:w #1#2
}
-\cs_new_protected_nopar:Npn \fp_ln_Taylor_aux:
+\cs_new:Npn \__fp_tan:w \s__fp \__fp_chk:w #1#2
{
- \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
- \if_int_compare:w
- \int_eval:w
- \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
- \if_int_compare:w \l_fp_output_extended_int < \c_one_thousand_million
- \else:
- \tex_advance:D \l_fp_output_decimal_int \c_one
- \tex_advance:D \l_fp_output_extended_int
- -\c_one_thousand_million
- \fi:
- \if_int_compare:w \l_fp_output_decimal_int < \c_one_thousand_million
- \else:
- \tex_advance:D \l_fp_output_integer_int \c_one
- \tex_advance:D \l_fp_output_decimal_int
- -\c_one_thousand_million
- \fi:
- \exp_after:wN \fp_ln_Taylor_aux:
+ \if_case:w #1 \exp_stop_f:
+ \__fp_case_return_same_o:w
+ \or:
+ \exp_after:wN \__fp_trig_exponent:NNNNwn
+ \exp_after:wN \__fp_tan_series:NNwww
+ \exp_after:wN 0
+ \exp_after:wN #2
+ \exp_after:wN \c_one
+ \or:
+ \__fp_case_use:nw
+ { \__fp_invalid_operation:Nnw \c_nan_fp { tan } }
+ \else: \__fp_case_return_same_o:w
\fi:
+ \s__fp \__fp_chk:w #1#2
}
-\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: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
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int
- = \c_zero
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int
- = \c_zero
- \cs_set_protected:Npx \fp_tmp:w ##1##2
- {
- \group_end:
- ##1 ##2 { \c_undefined_fp }
- }
- \else:
- \cs_set_protected:Npx \fp_tmp:w ##1##2
- {
- \group_end:
- ##1 ##2 { \c_zero_fp }
- }
- \fi:
- \else:
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int
- = \c_zero
- \cs_set_protected:Npx \fp_tmp:w ##1##2
- {
- \group_end:
- ##1 ##2 { \c_one_fp }
- }
- \else:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_pow_aux_i:
- \fi:
- \fi:
- \fp_tmp:w #1 #2
-}
-\cs_new_protected_nopar:Npn \fp_pow_aux_i:
- {
- \if_int_compare:w \l_fp_input_b_sign_int > \c_zero
- \tl_set:Nn \l_fp_sign_tl { + }
- \exp_after:wN \fp_pow_aux_ii:
- \else:
- \l_fp_input_a_extended_int \c_zero
- \if_int_compare:w \l_fp_input_a_exponent_int < \c_ten
- \group_begin:
- \fp_extended_normalise:
- \if_int_compare:w
- \int_eval:w
- \l_fp_input_a_decimal_int + \l_fp_input_a_extended_int
- = \c_zero
- \group_end:
- \tl_set:Nn \l_fp_sign_tl { - }
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \fp_pow_aux_ii:
+\cs_new:Npn \__fp_cot:w \s__fp \__fp_chk:w #1#2
+ {
+ \if_case:w #1 \exp_stop_f:
+ \exp_after:wN \__fp_one_over:w
+ \or:
+ \exp_after:wN \__fp_trig_exponent:NNNNwn
+ \exp_after:wN \__fp_tan_series:NNwww
+ \exp_after:wN 2
+ \exp_after:wN #2
+ \exp_after:wN \c_three
+ \or:
+ \__fp_case_use:nw
+ { \__fp_invalid_operation:Nnw \c_nan_fp { cot } }
+ \else: \__fp_case_return_same_o:w
+ \fi:
+ \s__fp \__fp_chk:w #1#2
+ }
+\cs_new:Npn \__fp_trig_exponent:NNNNwn #1#2#3#4 \s__fp \__fp_chk:w 1#5#6
+ {
+ \if_int_compare:w #6 > - \c_eight
+ \exp_after:wN #1
+ \exp_after:wN #2
+ \exp_after:wN #3
+ \int_use:N \__int_eval:w #4
+ \if_int_compare:w #6 > \c_zero
+ \exp_after:wN \__fp_trig_large:w \__int_value:w
\else:
- \group_end:
- \cs_set_protected:Npx \fp_tmp:w ##1##2
- {
- \group_end:
- ##1 ##2 { \c_undefined_fp }
- }
+ \exp_after:wN \__fp_trig_small:w \__int_value:w
\fi:
- \else:
- \cs_set_protected:Npx \fp_tmp:w ##1##2
- {
- \group_end:
- ##1 ##2 { \c_undefined_fp }
- }
+ \else:
+ \if_case:w #4
+ \__fp_sin_epsilon:w
+ \or: \__fp_sin_epsilon:w
+ \or: \__fp_cos_epsilon:w
+ \else: \__fp_cot_epsilon:w
\fi:
+ #5
\fi:
+ #6 ;
}
-\cs_new_protected_nopar:Npn \fp_pow_aux_ii:
+\cs_new:Npn \__fp_sin_epsilon:w #1 \fi: #2 \fi: #3 ;
+ { \fi: \fi: \__fp_exp_after_o:w \s__fp \__fp_chk:w 1 #2 {#3} }
+\cs_new:Npn \__fp_cos_epsilon:w #1 \fi: #2 \fi: #3 ; #4 ;
+ { \fi: \fi: \exp_after:wN \c_one_fp }
+\cs_new:Npn \__fp_cot_epsilon:w \fi: #1 \fi: #2 ;
+ { \fi: \fi: \__fp_one_over:w \s__fp \__fp_chk:w 1 #1 {#2} }
+\cs_new:Npn \__fp_trig_small:w #1;
{
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- \exp_after:wN \fp_pow_aux_iv:
- \else:
- \if_int_compare:w \l_fp_input_a_exponent_int < \c_ten
- \group_begin:
- \l_fp_input_a_extended_int \c_zero
- \fp_extended_normalise:
- \if_int_compare:w \l_fp_input_a_decimal_int = \c_zero
- \if_int_compare:w \l_fp_input_a_integer_int > \c_ten
- \group_end:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_pow_aux_iv:
- \else:
- \group_end:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \fp_pow_aux_iii:
- \fi:
+ \exp_after:wN \exp_after:wN \exp_after:wN \__fp_trig_small_aux:wwNN
+ \prg_replicate:nn { - #1 } { 0 } ;
+ }
+\cs_new:Npn \__fp_trig_small_aux:wwNN #1; #2#3#4#5;
+ {
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_pack_twice_four:wNNNNNNNN
+ \__fp_pack_twice_four:wNNNNNNNN
+ .
+ ;
+ #1#2#3#4#5 0000 0000;
+ }
+\cs_new:Npn \__fp_trig_large:w #1; #2#3;
+ { \__fp_trig_large_i:www #2; #3 ; #1; }
+\cs_new:Npn \__fp_trig_large_i:www #1; #2; #3;
+ {
+ \if_meaning:w 0 #3 \__fp_trig_large_break:w \fi:
+ \exp_after:wN \__fp_trig_large_ii:wnnnnnn
+ \int_use:N \__int_eval:w ( #1 - 3141 ) / 6283 ;
+ {#1} #2;
+ \int_use:N \__int_eval:w \c_minus_one + #3;
+ }
+\cs_new:Npn \__fp_trig_large_ii:wnnnnnn #1; #2#3#4#5;
+ {
+ \exp_after:wN \__fp_trig_large_i:www
+ \int_use:N \__int_eval:w -5 0000 + #20 - #1*62831
+ \exp_after:wN \__fp_fixed_mul_pack:NNNNNw
+ \int_use:N \__int_eval:w 4 9995 0000 + #30 - #1*8530
+ \exp_after:wN \__fp_fixed_mul_pack:NNNNNw
+ \int_use:N \__int_eval:w 4 9995 0000 + #40 - #1*7179
+ \exp_after:wN \__fp_fixed_mul_pack:NNNNNw
+ \int_use:N \__int_eval:w 5 0000 0000 + #50 - #1*5880
+ \exp_after:wN ;
+ \exp_after:wN ;
+ }
+\cs_new:Npn \__fp_trig_large_break:w \fi: #1; #2;
+ { \fi: \__fp_trig_octant_loop:nw #2 {0000} {0000} ; }
+\cs_new:Npn \__fp_trig_octant_loop:nw #1#2;
+ {
+ \if_int_compare:w #1 < 15707 \exp_stop_f:
+ \__fp_trig_octant_break:w
+ \fi:
+ + \c_two
+ \__fp_fixed_sub_back:wwN
+ {15707} {9632} {6794} {8970} {0000} {0000} ;
+ {#1} #2;
+ \__fp_trig_octant_loop:nw
+ }
+\cs_new:Npn \__fp_trig_octant_break:w #1 \fi: + #2#3 #4; #5#6; #7;
+ {
+ \fi:
+ \if_int_compare:w #5 < 7854 \exp_stop_f:
+ \if_int_compare:w #5 < \c_zero
+ \exp_after:wN \__fp_trig_octant_neg:w
+ \fi:
+ \exp_after:wN \__fp_use_i_until_s:nw
+ \exp_after:wN .
+ \fi:
+ + \c_one
+ \__fp_fixed_sub:wwN
+ {15707} {9632} {6794} {8970} {0000} {0000} ;
+ {#5} #6 ; . ;
+ }
+\cs_new:Npn \__fp_trig_octant_neg:w #1\fi: #2; #3#4#5#6#7#8; #9
+ {
+ \fi:
+ + \c_seven
+ \exp_after:wN \__fp_fixed_add_after:NNNNNwN
+ \int_use:N \__int_eval:w 1 9999 9998 - #30000 - #4
+ \exp_after:wN \__fp_fixed_add_pack:NNNNNwN
+ \int_use:N \__int_eval:w 1 9999 9998 - #5#6
+ \exp_after:wN \__fp_fixed_add_pack:NNNNNwN
+ \int_use:N \__int_eval:w 2 0000 0000 - #7#8 ; {#9} ;
+ }
+\cs_new:Npn \__fp_sin_series:NNwww #1#2#3 . #4; #5;
+ {
+ \__fp_fixed_mul:wwn #4; #4;
+ {
+ \exp_after:wN \__fp_sin_series_aux:Nnww
+ \__int_value:w
+ \if_int_odd:w \__int_eval:w ( #3 + \c_two ) / \c_four \__int_eval_end:
+ #2
\else:
- \group_end:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \exp_after:wN \exp_after:wN
- \exp_after:wN \fp_pow_aux_iv:
+ \if_meaning:w #2 0 2 \else: 0 \fi:
\fi:
- \else:
- \exp_after:wN \exp_after:wN \exp_after:wN
- \fp_pow_aux_iv:
- \fi:
+ {#3}
+ }
+ #4 ;
+ }
+\cs_new:Npn \__fp_sin_series_aux:Nnww #1#2 #3; #4;
+ {
+ \if_int_odd:w \__int_eval:w #2 / \c_two \__int_eval_end:
+ \exp_after:wN \use_i:nn
+ \else:
+ \exp_after:wN \use_ii:nn
\fi:
- \cs_set_protected:Npx \fp_tmp:w ##1##2
+ {
+ \__fp_fixed_continue:wn {0000}{0000}{0000}{0001}{5619}{2070}; % 1/18!
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{0000}{0000}{0477}{9477}{3324};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{0000}{0011}{4707}{4559}{7730};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{0000}{2087}{6756}{9878}{6810};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{0027}{5573}{1922}{3985}{8907};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{2480}{1587}{3015}{8730}{1587};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0013}{8888}{8888}{8888}{8888}{8889};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0416}{6666}{6666}{6666}{6666}{6667};
+ \__fp_fixed_mul_sub_back:wwwn #3; {5000}{0000}{0000}{0000}{0000}{0000};
+ \__fp_fixed_mul_sub_back:wwwn #3;{10000}{0000}{0000}{0000}{0000}{0000};
+ }
+ {
+ \__fp_fixed_continue:wn {0000}{0000}{0000}{0028}{1145}{7254}; % 1/17!
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{0000}{0000}{7647}{1637}{3182};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{0000}{0160}{5904}{3836}{8216};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{0002}{5052}{1083}{8544}{1719};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{0275}{5731}{9223}{9858}{9065};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0001}{9841}{2698}{4126}{9841}{2698};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0083}{3333}{3333}{3333}{3333}{3333};
+ \__fp_fixed_mul_sub_back:wwwn #3; {1666}{6666}{6666}{6666}{6666}{6667};
+ \__fp_fixed_mul_sub_back:wwwn #3;{10000}{0000}{0000}{0000}{0000}{0000};
+ \__fp_fixed_mul:wwn #4;
+ }
+ {
+ \exp_after:wN \__fp_sanitize:Nw
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w \__fp_fixed_to_float:wN
+ }
+ #1
+ }
+\cs_new:Npn \__fp_tan_series:NNwww #1#2#3. #4; #5;
+ {
+ \__fp_fixed_mul:wwn #4; #4;
+ {
+ \exp_after:wN \__fp_tan_series_aux:Nnww
+ \__int_value:w
+ \if_int_odd:w \__int_eval:w #3 / \c_two \__int_eval_end:
+ \exp_after:wN \reverse_if:N
+ \fi:
+ \if_meaning:w #1#2 2 \else: 0 \fi:
+ {#3}
+ }
+ #4 ;
+ }
+\cs_new:Npn \__fp_tan_series_aux:Nnww #1 #2 #3; #4;
+ {
+ \__fp_fixed_continue:wn {0000}{0000}{1527}{3493}{0856}{7059};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{0159}{6080}{0274}{5257}{6472};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0002}{4571}{2320}{0157}{2558}{8481};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0115}{5830}{7533}{5397}{3168}{2147};
+ \__fp_fixed_mul_sub_back:wwwn #3; {1929}{8245}{6140}{3508}{7719}{2982};
+ \__fp_fixed_mul_sub_back:wwwn #3;{10000}{0000}{0000}{0000}{0000}{0000};
+ \__fp_fixed_mul:wwn #4;
{
- \group_end:
- ##1 ##2
+ \__fp_fixed_continue:wn {0000}{0007}{0258}{0681}{9408}{4706};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0000}{2343}{7175}{1399}{6151}{7670};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0019}{2638}{4588}{9232}{8861}{3691};
+ \__fp_fixed_mul_sub_back:wwwn #3; {0536}{6357}{0691}{4344}{6852}{4252};
+ \__fp_fixed_mul_sub_back:wwwn #3; {5263}{1578}{9473}{6842}{1052}{6315};
+ \__fp_fixed_mul_sub_back:wwwn #3;{10000}{0000}{0000}{0000}{0000}{0000};
{
- \l_fp_sign_tl
- \int_use:N \l_fp_output_integer_int
- .
- \exp_after:wN \use_none:n
- \int_value:w \int_eval:w
- \l_fp_output_decimal_int + \c_one_thousand_million
- e
- \int_use:N \l_fp_output_exponent_int
+ \exp_after:wN \__fp_sanitize:Nw
+ \exp_after:wN #1
+ \int_use:N \__int_eval:w
+ \reverse_if:N \if_int_odd:w
+ \__int_eval:w (#2 - \c_one) / \c_two \__int_eval_end:
+ \exp_after:wN \__fp_reverse_args:Nww
+ \fi:
+ \__fp_fixed_div_to_float:ww
}
}
}
-\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
+%% File: l3fp-convert.dtx Copyright(C) 2011-2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\cs_new:Npn \__fp_trim_zeros:w #1 ;
+ {
+ \__fp_trim_zeros_loop:w #1
+ ; \__fp_trim_zeros_loop:w 0; \__fp_trim_zeros_dot:w .; \s__stop
+ }
+\cs_new:Npn \__fp_trim_zeros_loop:w #1 0; #2 { #2 #1 ; #2 }
+\cs_new:Npn \__fp_trim_zeros_dot:w #1 .; { \__fp_trim_zeros_end:w #1 ; }
+\cs_new:Npn \__fp_trim_zeros_end:w #1 ; #2 \s__stop { #1 }
+\tl_const:Nx \c__fp_scientific_inf_tl
+ { 1e \int_use:N \c__fp_max_exponent_int }
+\cs_new:Npn \fp_to_scientific:N #1 { \exp_after:wN \__fp_to_scientific:w #1 }
+\cs_generate_variant:Nn \fp_to_scientific:N { c }
+\cs_new:Npn \fp_to_scientific:n #1
+ {
+ \exp_after:wN \__fp_to_scientific:w
+ \tex_romannumeral:D -`0 \__fp_parse:n {#1}
+ }
+\cs_new:Npn \__fp_to_scientific:w \s__fp \__fp_chk:w #1#2#3 ;
+ {
+ \if_meaning:w 2 #2 \exp_after:wN - \tex_romannumeral:D -`0 \fi:
+ \if_case:w #1 \exp_stop_f:
+ \__fp_case_return:nw { \exp_after:wN 0 }
+ \or: \exp_after:wN \__fp_to_scientific_normal:wnnnnn
+ \or:
+ \__fp_case_use:nw
{
- \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_invalid_operation:Nnw
+ \c__fp_scientific_inf_tl { fp_to_scientific }
}
- \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_output_integer_int \l_fp_output_decimal_int
- \l_fp_output_extended_int
- \l_fp_output_exponent_int
- \int_eval:w
- \l_fp_input_a_exponent_int + \l_fp_input_b_exponent_int
- \scan_stop:
- \fp_extended_normalise_output:
- \tex_multiply:D \l_fp_input_a_sign_int \l_fp_input_b_sign_int
- \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_extended_int \l_fp_output_extended_int
- \l_fp_input_a_exponent_int \l_fp_output_exponent_int
- \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
- \cs_set_eq:NN \fp_exp_const:Nx \use_none:nn
- \fp_exp_internal:
+ \or:
+ \__fp_case_use:nw
+ { \__fp_invalid_operation:Nnw 0 { fp_to_scientific } }
+ \fi:
+ \s__fp \__fp_chk:w #1 #2 #3 ; \prg_do_nothing:
}
-\prg_new_conditional:Npnn \fp_if_undefined:N #1 { p , T , F , TF }
+\cs_new:Npn \__fp_to_scientific_normal:wnnnnn
+ \s__fp \__fp_chk:w 1 #1 #2 #3#4#5#6 ; \prg_do_nothing:
{
- \if_meaning:w #1 \c_undefined_fp
- \prg_return_true:
+ \if_int_compare:w #2 = \c_one
+ \exp_after:wN \__fp_to_scientific_normal:wNw
\else:
- \prg_return_false:
+ \exp_after:wN \__fp_to_scientific_normal:wNw
+ \exp_after:wN e
+ \int_use:N \__int_eval:w #2 - \c_one
\fi:
+ ; #3 #4 #5 #6 ;
}
-\prg_new_conditional:Npnn \fp_if_zero:N #1 { p , T , F , TF }
+\cs_new:Npn \__fp_to_scientific_normal:wNw #1 ; #2#3;
+ { \__fp_trim_zeros:w #2.#3 ; #1 }
+\tl_const:Nn \c__fp_decimal_inf_tl
{
- \if_meaning:w #1 \c_zero_fp
- \prg_return_true:
- \else:
- \prg_return_false:
+ \exp_after:wN \exp_after:wN \exp_after:wN 1
+ \prg_replicate:nn \c__fp_max_exponent_int 0
+ }
+\cs_new:Npn \fp_to_decimal:N #1 { \exp_after:wN \__fp_to_decimal:w #1 }
+\cs_generate_variant:Nn \fp_to_decimal:N { c }
+\cs_new_nopar:Npn \fp_to_decimal:n
+ {
+ \exp_after:wN \__fp_to_decimal:w
+ \tex_romannumeral:D -`0 \__fp_parse:n
+ }
+\cs_new:Npn \__fp_to_decimal:w \s__fp \__fp_chk:w #1#2#3 ;
+ {
+ \if_meaning:w 2 #2 \exp_after:wN - \tex_romannumeral:D -`0 \fi:
+ \if_case:w #1 \exp_stop_f:
+ \__fp_case_return:nw { \exp_after:wN 0 }
+ \or: \exp_after:wN \__fp_to_decimal_normal:wnnnnn
+ \or:
+ \__fp_case_use:nw
+ {
+ \__fp_invalid_operation:Nnw
+ \c__fp_decimal_inf_tl { fp_to_decimal }
+ }
+ \or:
+ \__fp_case_use:nw
+ { \__fp_invalid_operation:Nnw 0 { fp_to_decimal } }
\fi:
+ \s__fp \__fp_chk:w #1 #2 #3 ; \prg_do_nothing:
}
-\prg_new_protected_conditional:Npnn \fp_compare:nNn #1#2#3 { T , F , TF }
- {
- \group_begin:
- \fp_split:Nn a {#1}
- \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
- \fp_split:Nn b {#3}
- \fp_standardise:NNNN
- \l_fp_input_b_sign_int
- \l_fp_input_b_integer_int
- \l_fp_input_b_decimal_int
- \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 }
- {
- \group_begin:
- \fp_read:N #3
- \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_read:N #1
- \fp_compare_aux:N #2
- }
-\cs_new_protected:Npn \fp_compare_aux:N #1
- {
- \cs_if_exist:cTF { fp_compare_#1: }
- { \use:c { fp_compare_#1: } }
+\cs_new:Npn \__fp_to_decimal_normal:wnnnnn
+ \s__fp \__fp_chk:w 1 #1 #2 #3#4#5#6 ; \prg_do_nothing:
+ {
+ \int_compare:nNnTF {#2} > \c_zero
{
- \group_end:
- \prg_return_false:
+ \int_compare:nNnTF {#2} < \c_sixteen
+ {
+ \__fp_decimate:nNnnnn { \c_sixteen - #2 }
+ \__fp_to_decimal_large:Nnnw
+ }
+ {
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_to_decimal_huge:wnnnn
+ \prg_replicate:nn { #2 - \c_sixteen } { 0 } ;
+ }
+ {#3} {#4} {#5} {#6}
+ }
+ {
+ \exp_after:wN \__fp_trim_zeros:w
+ \exp_after:wN 0
+ \exp_after:wN .
+ \tex_romannumeral:D -`0 \prg_replicate:nn { - #2 } { 0 }
+ #3#4#5#6 ;
}
}
-\cs_new_protected_nopar:cpn { fp_compare_=: }
+\cs_new:Npn \__fp_to_decimal_large:Nnnw #1#2#3#4;
{
- \if_int_compare:w \l_fp_input_a_sign_int = \l_fp_input_b_sign_int
- \if_int_compare:w \l_fp_input_a_integer_int = \l_fp_input_b_integer_int
- \if_int_compare:w \l_fp_input_a_decimal_int = \l_fp_input_b_decimal_int
- \if_int_compare:w
- \l_fp_input_a_exponent_int = \l_fp_input_b_exponent_int
- \group_end:
- \prg_return_true:
- \else:
- \group_end:
- \prg_return_false:
- \fi:
- \else:
- \group_end:
- \prg_return_false:
- \fi:
- \else:
- \group_end:
- \prg_return_false:
+ \exp_after:wN \__fp_trim_zeros:w \__int_value:w
+ \if_int_compare:w #2 > \c_zero
+ #2
\fi:
- \else:
- \group_end:
- \prg_return_false:
- \fi:
+ \exp_stop_f:
+ #3.#4 ;
}
-\cs_new_protected_nopar:cpn { fp_compare_>: }
+\cs_new:Npn \__fp_to_decimal_huge:wnnnn #1; #2#3#4#5 { #2#3#4#5 #1 }
+\cs_new:Npn \fp_to_tl:N #1 { \exp_after:wN \__fp_to_tl:w #1 }
+\cs_generate_variant:Nn \fp_to_tl:N { c }
+\cs_new_nopar:Npn \fp_to_tl:n
{
- \if_int_compare:w \int_eval:w
- \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int
- = \c_zero
- \if_int_compare:w \int_eval:w
- \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int
- = \c_zero
- \group_end:
- \prg_return_false:
- \else:
- \if_int_compare:w \l_fp_input_b_sign_int > \c_zero
- \group_end:
- \prg_return_false:
- \else:
- \group_end:
- \prg_return_true:
- \fi:
- \fi:
- \else:
- \if_int_compare:w \int_eval:w
- \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int
- = \c_zero
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- \group_end:
- \prg_return_true:
- \else:
- \group_end:
- \prg_return_false:
- \fi:
- \else:
- \use:c { fp_compare_>_aux: }
- \fi:
- \fi:
+ \exp_after:wN \__fp_to_tl:w
+ \tex_romannumeral:D -`0 \__fp_parse:n
}
-\cs_new_protected_nopar:cpn { fp_compare_>_aux: }
+\cs_new:Npn \__fp_to_tl:w \s__fp \__fp_chk:w #1#2
{
- \if_int_compare:w \l_fp_input_a_sign_int > \l_fp_input_b_sign_int
- \group_end:
- \prg_return_true:
- \else:
- \if_int_compare:w \l_fp_input_a_sign_int < \l_fp_input_b_sign_int
- \group_end:
- \prg_return_false:
- \else:
- \if_int_compare:w \l_fp_input_a_sign_int > \c_zero
- \use:c { fp_compare_absolute_a>b: }
- \else:
- \use:c { fp_compare_absolute_a<b: }
- \fi:
- \fi:
+ \if_meaning:w 2 #2 \exp_after:wN - \tex_romannumeral:D -`0 \fi:
+ \if_case:w #1 \exp_stop_f:
+ \__fp_case_return:nw { 0 }
+ \or: \exp_after:wN \__fp_to_tl_normal:nnnnn
+ \or: \__fp_case_return:nw { inf }
+ \else: \__fp_case_return:nw { nan }
\fi:
}
-\cs_new_protected_nopar:cpn { fp_compare_absolute_a>b: }
+\cs_new:Npn \__fp_to_tl_normal:nnnnn #1#2 ;
{
- \if_int_compare:w \l_fp_input_a_exponent_int > \l_fp_input_b_exponent_int
- \group_end:
- \prg_return_true:
+ \if_int_compare:w #1 > \c_sixteen
+ \exp_after:wN \__fp_to_scientific_normal:wnnnnn
\else:
- \if_int_compare:w \l_fp_input_a_exponent_int < \l_fp_input_b_exponent_int
- \group_end:
- \prg_return_false:
+ \if_int_compare:w #1 < - \c_two
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_to_scientific_normal:wnnnnn
\else:
- \if_int_compare:w \l_fp_input_a_integer_int > \l_fp_input_b_integer_int
- \group_end:
- \prg_return_true:
- \else:
- \if_int_compare:w
- \l_fp_input_a_integer_int < \l_fp_input_b_integer_int
- \group_end:
- \prg_return_false:
- \else:
- \if_int_compare:w
- \l_fp_input_a_decimal_int > \l_fp_input_b_decimal_int
- \group_end:
- \prg_return_true:
- \else:
- \group_end:
- \prg_return_false:
- \fi:
- \fi:
- \fi:
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_to_decimal_normal:wnnnnn
\fi:
\fi:
+ \s__fp \__fp_chk:w 1 0 {#1} #2 ; \prg_do_nothing:
}
-\cs_new_protected_nopar:cpn { fp_compare_absolute_a<b: }
+\cs_new:Npn \fp_to_dim:N #1 { \fp_to_decimal:N #1 pt }
+\cs_generate_variant:Nn \fp_to_dim:N { c }
+\cs_new:Npn \fp_to_dim:n #1 { \fp_to_decimal:n {#1} pt }
+\cs_new:Npn \fp_to_int:N #1 { \exp_after:wN \__fp_to_int:w #1 }
+\cs_generate_variant:Nn \fp_to_int:N { c }
+\cs_new_nopar:Npn \fp_to_int:n
{
- \if_int_compare:w \l_fp_input_b_exponent_int > \l_fp_input_a_exponent_int
- \group_end:
- \prg_return_true:
- \else:
- \if_int_compare:w \l_fp_input_b_exponent_int < \l_fp_input_a_exponent_int
- \group_end:
- \prg_return_false:
- \else:
- \if_int_compare:w \l_fp_input_b_integer_int > \l_fp_input_a_integer_int
- \group_end:
- \prg_return_true:
- \else:
- \if_int_compare:w
- \l_fp_input_b_integer_int < \l_fp_input_a_integer_int
- \group_end:
- \prg_return_false:
- \else:
- \if_int_compare:w
- \l_fp_input_b_decimal_int > \l_fp_input_a_decimal_int
- \group_end:
- \prg_return_true:
- \else:
- \group_end:
- \prg_return_false:
- \fi:
- \fi:
- \fi:
- \fi:
- \fi:
+ \exp_after:wN \__fp_to_int:w
+ \tex_romannumeral:D -`0 \__fp_parse:n
}
-\cs_new_protected_nopar:cpn { fp_compare_<: }
+\cs_new:Npn \__fp_to_int:w #1;
{
- \tl_set:Nx \l_fp_internal_tl
- {
- \int_set:Nn \exp_not:N \l_fp_input_a_sign_int
- { \int_use:N \l_fp_input_b_sign_int }
- \int_set:Nn \exp_not:N \l_fp_input_a_integer_int
- { \int_use:N \l_fp_input_b_integer_int }
- \int_set:Nn \exp_not:N \l_fp_input_a_decimal_int
- { \int_use:N \l_fp_input_b_decimal_int }
- \int_set:Nn \exp_not:N \l_fp_input_a_exponent_int
- { \int_use:N \l_fp_input_b_exponent_int }
- \int_set:Nn \exp_not:N \l_fp_input_b_sign_int
- { \int_use:N \l_fp_input_a_sign_int }
- \int_set:Nn \exp_not:N \l_fp_input_b_integer_int
- { \int_use:N \l_fp_input_a_integer_int }
- \int_set:Nn \exp_not:N \l_fp_input_b_decimal_int
- { \int_use:N \l_fp_input_a_decimal_int }
- \int_set:Nn \exp_not:N \l_fp_input_b_exponent_int
- { \int_use:N \l_fp_input_a_exponent_int }
- }
- \l_fp_internal_tl
- \use:c { fp_compare_>: }
+ \exp_after:wN \__fp_to_decimal:w \tex_romannumeral:D -`0
+ \__fp_round:Nwn \__fp_round_to_nearest:NNN #1; { 0 } \prg_do_nothing:
}
-\prg_new_protected_conditional:Npnn \fp_compare:n #1 { T , F , TF }
+\cs_new:Npn \dim_to_fp:n #1
{
- \group_begin:
- \tl_set:Nx \l_fp_internal_tl
- {
- \group_end:
- \fp_compare_aux_i:w #1 \exp_not:n { == \q_nil == \q_stop }
- }
- \l_fp_internal_tl
+ \exp_after:wN \__fp_from_dim_test:N
+ \__int_value:w \etex_glueexpr:D #1 ;
}
-\cs_new_protected:Npn \fp_compare_aux_i:w #1 == #2 == #3 \q_stop
+\cs_new:Npn \__fp_from_dim_test:N #1
{
- \quark_if_nil:nTF {#2}
- { \fp_compare_aux_ii:w #1 != \q_nil != \q_stop }
- { \fp_compare:nNnTF {#1} = {#2} \prg_return_true: \prg_return_false: }
+ \if_meaning:w 0 #1
+ \exp_after:wN \__fp_use_i_until_s:nw
+ \exp_after:wN \c_zero_fp
+ \else:
+ \if_meaning:w - #1
+ \exp_after:wN \__fp_from_dim:Nw
+ \exp_after:wN 2
+ \__int_value:w
+ \else:
+ \exp_after:wN \__fp_from_dim:Nw
+ \exp_after:wN 0
+ \__int_value:w #1
+ \fi:
+ \fi:
+ }
+\cs_new:Npn \__fp_from_dim:Nw #1 #2;
+ {
+ \__fp_pack_twice_four:wNNNNNNNN \__fp_from_dim_ii:wNNnnnnnn ;
+ #2 000 0000 00 {10}987654321; #1
}
-\cs_new_protected:Npn \fp_compare_aux_ii:w #1 != #2 != #3 \q_stop
+\cs_new:Npn \__fp_from_dim_ii:wNNnnnnnn #1; #2#3#4#5#6#7#8#9
+ { \__fp_from_dim_iii:wnnnnwN #1 {#2#300} {0000} ; }
+\cs_new:Npn \__fp_from_dim_iii:wnnnnwN #1; #2#3#4#5#6; #7
{
- \quark_if_nil:nTF {#2}
- { \fp_compare_aux_iii:w #1 <= \q_nil <= \q_stop }
- { \fp_compare:nNnTF {#1} = {#2} \prg_return_false: \prg_return_true: }
+ \__fp_mul_npos:Nnwnw #7 {#5} #1 ;
+ {-4} {1525} {8789} {0625} {0000} ;
}
-\cs_new_protected:Npn \fp_compare_aux_iii:w #1 <= #2 <= #3 \q_stop
+\cs_new_eq:NN \fp_use:N \fp_to_decimal:N
+\cs_generate_variant:Nn \fp_use:N { c }
+\cs_new_eq:NN \fp_eval:n \fp_to_decimal:n
+\cs_new:Npn \fp_abs:n #1 { \fp_to_decimal:n { abs ( #1 ) } }
+%%
+%% File: l3fp-assign.dtx Copyright (C) 2011-2012 The LaTeX3 project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\cs_new_protected:Npn \fp_new:N #1
+ { \cs_new_eq:NN #1 \c_zero_fp }
+\cs_generate_variant:Nn \fp_new:N {c}
+\cs_new_protected:Npn \fp_set:Nn #1#2
+ { \tl_set:Nx #1 { \__fp_parse:n {#2} } }
+\cs_new_protected:Npn \fp_gset:Nn #1#2
+ { \tl_gset:Nx #1 { \__fp_parse:n {#2} } }
+\cs_new_protected:Npn \fp_const:Nn #1#2
+ { \tl_const:Nx #1 { \__fp_parse:n {#2} } }
+\cs_generate_variant:Nn \fp_set:Nn {c}
+\cs_generate_variant:Nn \fp_gset:Nn {c}
+\cs_generate_variant:Nn \fp_const:Nn {c}
+\cs_new_eq:NN \fp_set_eq:NN \tl_set_eq:NN
+\cs_new_eq:NN \fp_gset_eq:NN \tl_gset_eq:NN
+\cs_generate_variant:Nn \fp_set_eq:NN { c , Nc , cc }
+\cs_generate_variant:Nn \fp_gset_eq:NN { c , Nc , cc }
+\cs_new_protected:Npn \fp_zero:N #1 { \fp_set_eq:NN #1 \c_zero_fp }
+\cs_new_protected:Npn \fp_gzero:N #1 { \fp_gset_eq:NN #1 \c_zero_fp }
+\cs_generate_variant:Nn \fp_zero:N { c }
+\cs_generate_variant:Nn \fp_gzero:N { c }
+\cs_new_protected:Npn \fp_zero_new:N #1
+ { \fp_if_exist:NTF #1 { \fp_zero:N #1 } { \fp_new:N #1 } }
+\cs_new_protected:Npn \fp_gzero_new:N #1
+ { \fp_if_exist:NTF #1 { \fp_gzero:N #1 } { \fp_new:N #1 } }
+\cs_generate_variant:Nn \fp_zero_new:N { c }
+\cs_generate_variant:Nn \fp_gzero_new:N { c }
+\cs_new_protected_nopar:Npn \fp_add:Nn { \__fp_add:NNNn \fp_set:Nn + }
+\cs_new_protected_nopar:Npn \fp_gadd:Nn { \__fp_add:NNNn \fp_gset:Nn + }
+\cs_new_protected_nopar:Npn \fp_sub:Nn { \__fp_add:NNNn \fp_set:Nn - }
+\cs_new_protected_nopar:Npn \fp_gsub:Nn { \__fp_add:NNNn \fp_gset:Nn - }
+\cs_new_protected:Npn \__fp_add:NNNn #1#2#3#4 { #1 #3 { #3 #2 (#4) } }
+\cs_generate_variant:Nn \fp_add:Nn { c }
+\cs_generate_variant:Nn \fp_gadd:Nn { c }
+\cs_generate_variant:Nn \fp_sub:Nn { c }
+\cs_generate_variant:Nn \fp_gsub:Nn { c }
+\cs_new_protected:Npn \fp_show:N #1
+ { \__msg_show_variable:x { > \fp_to_tl:N #1 } }
+\cs_new_protected:Npn \fp_show:n #1
+ { \__msg_show_variable:x { > \fp_to_tl:n {#1} } }
+\cs_generate_variant:Nn \fp_show:N { c }
+\fp_const:Nn \c_e_fp { 2.718 2818 2845 9045 }
+\fp_const:Nn \c_one_fp { 1 }
+\fp_const:Nn \c_pi_fp { 3.141 5926 5358 9794 }
+\fp_const:Nn \c_one_degree_fp { 0.0 1745 3292 5199 4330 }
+\fp_new:N \l_tmpa_fp
+\fp_new:N \l_tmpb_fp
+\fp_new:N \g_tmpa_fp
+\fp_new:N \g_tmpb_fp
+%% File: l3fp-old.dtx Copyright (C) 2012 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3kernel bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX3 Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\fp_const:Nn \c_undefined_fp { nan }
+\prg_new_conditional:Npnn \fp_if_undefined:N #1 { p , T , F , TF }
+ { \exp_after:wN \__fp_if_undefined:w #1 }
+\cs_new:Npn \__fp_if_undefined:w \s__fp \__fp_chk:w #1#2;
{
- \quark_if_nil:nTF {#2}
- { \fp_compare_aux_iv:w #1 >= \q_nil >= \q_stop }
- { \fp_compare:nNnTF {#1} > {#2} \prg_return_false: \prg_return_true: }
+ \if_int_compare:w #1 > \c_one
+ \prg_return_true: \else: \prg_return_false: \fi:
}
-\cs_new_protected:Npn \fp_compare_aux_iv:w #1 >= #2 >= #3 \q_stop
+\prg_new_conditional:Npnn \fp_if_zero:N #1 { p , T , F , TF }
+ { \exp_after:wN \__fp_if_zero:w #1 }
+\cs_new:Npn \__fp_if_zero:w \s__fp \__fp_chk:w #1#2;
+ { \if_meaning:w #1 0 \prg_return_true: \else: \prg_return_false: \fi: }
+\cs_new_protected_nopar:Npn \fp_abs:N { \__fp_abs:NNN \tl_set:Nx \__fp_abs:w }
+\cs_new_protected_nopar:Npn \fp_gabs:N { \__fp_abs:NNN \tl_gset:Nx \__fp_abs:w }
+\cs_new_protected_nopar:Npn \fp_neg:N { \__fp_abs:NNN \tl_set:Nx \__fp_neg:w }
+\cs_new_protected_nopar:Npn \fp_gneg:N { \__fp_abs:NNN \tl_gset:Nx \__fp_neg:w }
+\cs_new_protected:Npn \__fp_abs:NNN #1#2#3
+ { #1 #3 { \exp_after:wN #2 #3 \prg_do_nothing: } }
+\cs_generate_variant:Nn \fp_abs:N { c }
+\cs_generate_variant:Nn \fp_gabs:N { c }
+\cs_generate_variant:Nn \fp_neg:N { c }
+\cs_generate_variant:Nn \fp_gneg:N { c }
+\cs_new_protected_nopar:Npn \fp_mul:Nn { \__fp_mul:NNNn \fp_set:Nn * }
+\cs_new_protected_nopar:Npn \fp_gmul:Nn { \__fp_mul:NNNn \fp_gset:Nn * }
+\cs_new_protected_nopar:Npn \fp_div:Nn { \__fp_mul:NNNn \fp_set:Nn / }
+\cs_new_protected_nopar:Npn \fp_gdiv:Nn { \__fp_mul:NNNn \fp_gset:Nn / }
+\cs_new_protected_nopar:Npn \fp_pow:Nn { \__fp_mul:NNNn \fp_set:Nn ^ }
+\cs_new_protected_nopar:Npn \fp_gpow:Nn { \__fp_mul:NNNn \fp_gset:Nn ^ }
+\cs_new_protected:Npn \__fp_mul:NNNn #1#2#3#4 { #1 #3 { #3 #2 (#4) } }
+\cs_generate_variant:Nn \fp_mul:Nn { c }
+\cs_generate_variant:Nn \fp_gmul:Nn { c }
+\cs_generate_variant:Nn \fp_div:Nn { c }
+\cs_generate_variant:Nn \fp_gdiv:Nn { c }
+\cs_generate_variant:Nn \fp_pow:Nn { c }
+\cs_generate_variant:Nn \fp_gpow:Nn { c }
+\cs_set_protected:Npn \__fp_tmp:w #1#2#3#4#5
{
- \quark_if_nil:nTF {#2}
- { \fp_compare_aux_v:w #1 = \q_nil \q_stop }
- { \fp_compare:nNnTF {#1} < {#2} \prg_return_false: \prg_return_true: }
+ \cs_new_protected_nopar:Npn #1 { #5 {#4} \tl_set_eq:NN #3 }
+ \cs_new_protected_nopar:Npn #2 { #5 {#4} \tl_gset_eq:NN #3 }
+ \cs_generate_variant:Nn #1 { c }
+ \cs_generate_variant:Nn #2 { c }
}
-\cs_new_protected:Npn \fp_compare_aux_v:w #1 = #2 = #3 \q_stop
+\__fp_tmp:w \fp_exp:Nn \fp_gexp:Nn \__fp_exp:w {exp} \__fp_assign_to:nNNNn
+\__fp_tmp:w \fp_ln:Nn \fp_gln:Nn \__fp_ln:w {ln } \__fp_assign_to:nNNNn
+\__fp_tmp:w \fp_sin:Nn \fp_gsin:Nn \__fp_sin:w {sin} \__fp_assign_to:nNNNn
+\__fp_tmp:w \fp_cos:Nn \fp_gcos:Nn \__fp_cos:w {cos} \__fp_assign_to:nNNNn
+\__fp_tmp:w \fp_tan:Nn \fp_gtan:Nn \__fp_tan:w {tan} \__fp_assign_to:nNNNn
+\cs_new_protected:Npn \__fp_assign_to:nNNNn #1#2#3#4#5
{
- \quark_if_nil:nTF {#2}
- { \fp_compare_aux_vi:w #1 < \q_nil < \q_stop }
- { \fp_compare:nNnTF {#1} = {#2} \prg_return_true: \prg_return_false: }
+ \exp_after:wN \__fp_assign_to_i:wNNNn
+ \tex_romannumeral:D -`0 \__fp_parse:n {#5} {#1} #2#3#4
}
-\cs_new_protected:Npn \fp_compare_aux_vi:w #1 < #2 < #3 \q_stop
+\cs_new_protected:Npn \__fp_assign_to_i:wNNNn \s__fp \__fp_chk:w #1#2#3; #4
{
- \quark_if_nil:nTF {#2}
- { \fp_compare_aux_vii:w #1 > \q_nil > \q_stop }
- { \fp_compare:nNnTF {#1} < {#2} \prg_return_true: \prg_return_false: }
+ \exp_args:Nc \__fp_assign_to_ii:NnNNN
+ { c__fp_ #4 ( #2 \if_meaning:w 1 #1 #3 \fi: ) _fp }
+ { #1#2#3 }
}
-\cs_new_protected:Npn \fp_compare_aux_vii:w #1 > #2 > #3 \q_stop
+\cs_new_protected:Npn \__fp_assign_to_ii:NnNNN #1#2#3#4#5
{
- \quark_if_nil:nTF {#2}
- { \prg_return_false: }
- { \fp_compare:nNnTF {#1} > {#2} \prg_return_true: \prg_return_false: }
+ \cs_if_exist:NF #1
+ { \tl_const:Nx #1 { #4 \s__fp \__fp_chk:w #2; } }
+ #3 #5 #1
}
-\msg_kernel_new:nnnn { fpu } { overflow }
- { Number~too~big. }
+\cs_new_protected_nopar:Npn \fp_compare:NNNTF { \fp_compare:nNnTF }
+\cs_new_protected_nopar:Npn \fp_compare:NNNT { \fp_compare:nNnT }
+\cs_new_protected_nopar:Npn \fp_compare:NNNF { \fp_compare:nNnF }
+\cs_new_protected_nopar:Npn \fp_compare_p:NNN { \fp_compare_p:nNn }
+\cs_new_protected_nopar:Npn \fp_round_places:Nn
+ { \__fp_round_places:NNn \tl_set:Nx }
+\cs_new_protected_nopar:Npn \fp_ground_places:Nn
+ { \__fp_round_places:NNn \tl_gset:Nx }
+\cs_new_protected:Npn \__fp_round_places:NNn #1#2#3
{
- The~input~given~is~too~big~for~the~LaTeX~floating~point~unit. \\
- Further~errors~may~well~occur!
+ #1 #2
+ {
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_round:Nwn
+ \exp_after:wN \exp_after:wN
+ \exp_after:wN \__fp_round_to_nearest:NNN
+ \exp_after:wN #2
+ \exp_after:wN { \int_use:N \__int_eval:w #3 }
+ }
}
-\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. }
+\cs_generate_variant:Nn \fp_round_places:Nn { c }
+\cs_generate_variant:Nn \fp_ground_places:Nn { c }
+\cs_new_protected:Npn \fp_round_figures:Nn #1#2
{
- The~exponent~of~the~input~given~is~too~big~for~the~floating~point~
- unit:~the~maximum~input~value~for~an~exponent~is~230.
+ \__fp_round_places:NNn \tl_set:Nx #1
+ { #2 - \exp_after:wN \__fp_exponent:w #1 }
}
-\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. }
+\cs_new_protected:Npn \fp_ground_figures:Nn #1#2
{
- The~trigonometry~code~can~only~work~with~numbers~smaller~
- than~1000000000.
+ \__fp_round_places:NNn \tl_gset:Nx #1
+ { #2 - \exp_after:wN \__fp_exponent:w #1 }
}
-\cs_new_protected_nopar:Npn \fp_trig_overflow_msg:
- { \msg_kernel_error:nn { fpu } { trigonometric-overflow } }
+\cs_generate_variant:Nn \fp_round_figures:Nn { c }
+\cs_generate_variant:Nn \fp_ground_figures:Nn { c }
%%
%%
%% End of file `l3fp.sty'.