summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-09-05 22:58:18 +0000
committerKarl Berry <karl@freefriends.org>2012-09-05 22:58:18 +0000
commitc556c94cbf233fa607dc3ac6a664f23efba92c07 (patch)
treefd6e97db5854a06159dea563eff175ea9e588a7c /Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
parente5a6b18348ead0cec45f680a2bacf024120cfdec (diff)
latex3
git-svn-id: svn://tug.org/texlive/trunk@27600 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.sty133
1 files changed, 84 insertions, 49 deletions
diff --git a/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty b/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
index cd23b05bfc1..eac513e519c 100644
--- a/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
+++ b/Master/texmf-dist/tex/latex/l3kernel/l3fp.sty
@@ -108,7 +108,7 @@
\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 ; }
+ { \fp_to_tl:n { \s__fp \__fp_chk:w #1 ; } }
}
\__scan_new:N \s__fp_mark
\__scan_new:N \s__fp_stop
@@ -214,6 +214,13 @@
\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} ; }
+\cs_new:Npn \__fp_exp_after_array_f:w #1
+ {
+ \cs:w __fp_exp_after \__fp_type_from_scan:N #1 _f:nw \cs_end:
+ { \__fp_exp_after_array_f:w }
+ #1
+ }
+\cs_new_eq:NN \__fp_exp_after_stop_f:nw \use_none:nn
\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 }
@@ -328,7 +335,7 @@
\exp_after:wN \use_i:nn
\fi:
}
-\cs_new:Npn \__fp_array_count:w #1 @
+\cs_new:Npn \__fp_array_count:n #1
{
\int_use:N \__int_eval:w \c_zero
\__fp_array_count_loop:Nw #1 { ? \__prg_break: } ;
@@ -337,6 +344,19 @@
}
\cs_new:Npn \__fp_array_count_loop:Nw #1#2;
{ \use_none:n #1 + \c_one \__fp_array_count_loop:Nw }
+\cs_new:Npn \__fp_expand:n #1
+ {
+ \__fp_expand_loop:nwnN { }
+ #1 \prg_do_nothing:
+ \s__fp_mark { } \__fp_expand_loop:nwnN
+ \s__fp_mark { } \__fp_use_i_until_s:nw ;
+ }
+\cs_new:Npn \__fp_expand_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_kernel_new:nnnn { kernel } { misused-fp }
{ A~floating~point~with~value~'#1'~was~misused. }
{
@@ -421,7 +441,7 @@
{ \cs_set:Npn \__fp_invalid_operation:nnw ##1##2##3; }
{
#1
- \__fp_error:nnfn { invalid } {##2} { \__fp_to_tl:w ##3; } { }
+ \__fp_error:nnfn { invalid } {##2} { \fp_to_tl:n { ##3; } } { }
\fp_flag_on:n { invalid_operation }
##1
}
@@ -430,7 +450,7 @@
{
#1
\__fp_error:nffn { invalid-ii }
- { \__fp_to_tl:w ##2; } { \__fp_to_tl:w ##3; } {##1}
+ { \fp_to_tl:n { ##2; } } { \fp_to_tl:n { ##3; } } {##1}
\fp_flag_on:n { invalid_operation }
\exp_after:wN \c_nan_fp
}
@@ -455,7 +475,7 @@
{ \cs_set:Npn \__fp_division_by_zero_o:Nnw ##1##2##3; }
{
#1
- \__fp_error:nnfn { zero-div } {##2} { \__fp_to_tl:w ##3; } { }
+ \__fp_error:nnfn { zero-div } {##2} { \fp_to_tl:n { ##3; } } { }
\fp_flag_on:n { division_by_zero }
\exp_after:wN ##1
}
@@ -464,7 +484,7 @@
{
#1
\__fp_error:nffn { zero-div-ii }
- { \__fp_to_tl:w ##3; } { \__fp_to_tl:w ##4; } {##2}
+ { \fp_to_tl:n { ##3; } } { \fp_to_tl:n { ##4; } } {##2}
\fp_flag_on:n { division_by_zero }
\exp_after:wN ##1
}
@@ -493,7 +513,7 @@
#1
\__fp_error:nffn
{ flow \if_meaning:w 1 ##1 -to \fi: }
- { \__fp_to_tl:w \s__fp \__fp_chk:w ##1##2##3; }
+ { \fp_to_tl:n { \s__fp \__fp_chk:w ##1##2##3; } }
{ \token_if_eq_meaning:NNF 0 ##2 { - } #4 }
{#2}
\fp_flag_on:n {#2}
@@ -869,20 +889,21 @@
}
\cs_new:Npn \__fp_parse_operand_relax:NN #1#2
{
- \cs:w __fp_exp_after \__fp_type_from_scan:N #2 _f:nw \cs_end:
+ \cs:w __fp_parse_exp_after \__fp_type_from_scan:N #2 _f:nw \cs_end:
{
\exp_after:wN \__fp_parse_infix:NN
\exp_after:wN #1 \tex_romannumeral:D \__fp_parse_expand:w
}
#2
}
-\cs_new:Npn \__fp_exp_after_mark_f:nw #1
+\cs_new_eq:NN \__fp_parse_exp_after_f:nw \__fp_exp_after_f:nw
+\cs_new:Npn \__fp_parse_exp_after_mark_f:nw #1
{
\__msg_kernel_expandable_error:nn { kernel } { fp-early-end }
\exp_after:wN \c_nan_fp
\tex_romannumeral:D -`0 #1
}
-\cs_new:cpn { __fp_exp_after_?_f:nw } #1#2
+\cs_new:cpn { __fp_parse_exp_after_?_f:nw } #1#2
{
\__msg_kernel_expandable_error:nnn
{ kernel } { bad-variable } {#2}
@@ -1367,7 +1388,7 @@
\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_eq:NN \__fp_parse_stop_until:N \use_none:n
\cs_new:Npn \__fp_parse_infix_after_operand:NwN #1 #2;
{
\__fp_exp_after_f:nw { \__fp_parse_infix:NN #1 }
@@ -1534,7 +1555,7 @@
{ #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:
+ \if_case:w \__int_eval:w \__fp_array_count:n {#3} - \c_one \__int_eval_end:
\__fp_round:Nwn #2 #3 {0} \tex_romannumeral:D
\or: \__fp_round:Nww #2 #3 \tex_romannumeral:D
\else:
@@ -1561,8 +1582,8 @@
\__fp_parse_expand:w
}
}
-\__fp_tmp:w - { neg }
-\__fp_tmp:w ! { not }
+\__fp_tmp:w - { - }
+\__fp_tmp:w ! { ! }
\group_begin:
\char_set_catcode_letter:N \)
\cs_new:cpn { __fp_parse_prefix_(:Nw } #1
@@ -1592,13 +1613,6 @@
}
}
\group_end:
-\cs_new:Npn \__fp_exp_after_array_f:w #1
- {
- \cs:w __fp_exp_after \__fp_type_from_scan:N #1 _f:nw \cs_end:
- { \__fp_exp_after_array_f:w }
- #1
- }
-\cs_new:Npn \__fp_exp_after_stop_f:nw #1#2 { }
\cs_new:cpn {__fp_parse_prefix_.:Nw} #1
{
\exp_after:wN \__fp_parse_infix_after_operand:NwN
@@ -2090,7 +2104,7 @@
{ \fi: \fi: #2 }
\cs_new:Npn \__fp_minmax_break_o:w #1 \fi: \fi: #2 \s__fp #3; #4;
{ \fi: \__fp_exp_after_o:w \s__fp #3; }
-\cs_new:Npn \__fp_not_o:w \s__fp \__fp_chk:w #1#2;
+\cs_new:cpn { __fp_!_o:w } \s__fp \__fp_chk:w #1#2;
{
\if_meaning:w 0 #1
\exp_after:wN \exp_after:wN \exp_after:wN \c_one_fp
@@ -2773,7 +2787,7 @@
\__int_value:w \__fp_round_digit:Nw #7 #8 ;
\exp_after:wN ;
}
-\cs_new:Npn \__fp_neg_o:w #1 \s__fp \__fp_chk:w #2 #3
+\cs_new:cpn { __fp_-_o:w } #1 \s__fp \__fp_chk:w #2 #3
{
\exp_after:wN \__fp_exp_after_o:w
\exp_after:wN \s__fp
@@ -3775,7 +3789,7 @@
\cs_new:Npn \__fp_pow_neg:www \s__fp \__fp_chk:w #1#2; #3; #4;
{
\if_case:w \__fp_pow_neg_case:w #4 ;
- \exp_after:wN \__fp_neg_o:w
+ \cs:w __fp_-_o:w \exp_after:wN \cs_end:
\or:
\if_int_compare:w \__int_eval:w #1 / \c_two = \c_one
\__fp_invalid_operation_o:Nww ^ #3; #4;
@@ -4193,11 +4207,12 @@
\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 }
-\cs_new:Npn \fp_to_scientific:N #1 { \exp_after:wN \__fp_to_scientific:w #1 }
+\cs_new:Npn \fp_to_scientific:N #1
+ { \exp_after:wN \__fp_to_scientific_dispatch:w #1 }
\cs_generate_variant:Nn \fp_to_scientific:N { c }
\cs_new_nopar:Npn \fp_to_scientific:n
{
- \exp_after:wN \__fp_to_scientific:w
+ \exp_after:wN \__fp_to_scientific_dispatch:w
\tex_romannumeral:D -`0 \__fp_parse:n
}
\group_begin:
@@ -4205,7 +4220,7 @@
\tl_to_lowercase:n
{
\group_end:
- \cs_new:Npn \__fp_to_scientific:w \s__fp \__fp_chk:w #1#2
+ \cs_new:Npn \__fp_to_scientific_dispatch:w \s__fp \__fp_chk:w #1#2
{
\if_meaning:w 2 #2 \exp_after:wN - \tex_romannumeral:D -`0 \fi:
\if_case:w #1 \exp_stop_f:
@@ -4247,14 +4262,15 @@
}
\cs_new:Npn \__fp_to_scientific_normal:wNw #1 ; #2#3;
{ \__fp_trim_zeros:w #2.#3 ; #1 }
-\cs_new:Npn \fp_to_decimal:N #1 { \exp_after:wN \__fp_to_decimal:w #1 }
+\cs_new:Npn \fp_to_decimal:N #1
+ { \exp_after:wN \__fp_to_decimal_dispatch: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
+ \exp_after:wN \__fp_to_decimal_dispatch:w
\tex_romannumeral:D -`0 \__fp_parse:n
}
-\cs_new:Npn \__fp_to_decimal:w \s__fp \__fp_chk:w #1#2
+\cs_new:Npn \__fp_to_decimal_dispatch:w \s__fp \__fp_chk:w #1#2
{
\if_meaning:w 2 #2 \exp_after:wN - \tex_romannumeral:D -`0 \fi:
\if_case:w #1 \exp_stop_f:
@@ -4315,14 +4331,14 @@
#3.#4 ;
}
\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_new:Npn \fp_to_tl:N #1 { \exp_after:wN \__fp_to_tl_dispatch:w #1 }
\cs_generate_variant:Nn \fp_to_tl:N { c }
\cs_new_nopar:Npn \fp_to_tl:n
{
- \exp_after:wN \__fp_to_tl:w
+ \exp_after:wN \__fp_to_tl_dispatch:w
\tex_romannumeral:D -`0 \__fp_parse:n
}
-\cs_new:Npn \__fp_to_tl:w \s__fp \__fp_chk:w #1#2
+\cs_new:Npn \__fp_to_tl_dispatch:w \s__fp \__fp_chk:w #1#2
{
\if_meaning:w 2 #2 \exp_after:wN - \tex_romannumeral:D -`0 \fi:
\if_case:w #1 \exp_stop_f:
@@ -4352,16 +4368,16 @@
\cs_generate_variant:Nn \fp_to_dim:N { c }
\cs_new:Npx \fp_to_dim:n #1
{ \exp_not:N \fp_to_decimal:n {#1} \tl_to_str:n {pt} }
-\cs_new:Npn \fp_to_int:N #1 { \exp_after:wN \__fp_to_int:w #1 }
+\cs_new:Npn \fp_to_int:N #1 { \exp_after:wN \__fp_to_int_dispatch:w #1 }
\cs_generate_variant:Nn \fp_to_int:N { c }
\cs_new_nopar:Npn \fp_to_int:n
{
- \exp_after:wN \__fp_to_int:w
+ \exp_after:wN \__fp_to_int_dispatch:w
\tex_romannumeral:D -`0 \__fp_parse:n
}
-\cs_new:Npn \__fp_to_int:w #1;
+\cs_new:Npn \__fp_to_int_dispatch:w #1;
{
- \exp_after:wN \__fp_to_decimal:w \tex_romannumeral:D -`0
+ \exp_after:wN \__fp_to_decimal_dispatch:w \tex_romannumeral:D -`0
\__fp_round:Nwn \__fp_round_to_nearest:NNN #1; { 0 }
}
\cs_new:Npn \dim_to_fp:n #1
@@ -4405,19 +4421,28 @@
{ \fp_to_decimal:n { abs \__fp_parse:n {#1} } }
\cs_new:Npn \__fp_array_to_clist:n #1
{
- \__fp_array_to_clist_i:wwww ;
- #1
- \__fp_array_to_clist_ii:ww \s__fp ; @
- ; , ~ , ~ @ \s_stop
+ \tl_if_empty:nF {#1}
+ {
+ \__fp_expand:n
+ {
+ { \use_ii:nn }
+ \__fp_array_to_clist_loop:Nw #1 { ? \__prg_break: } ;
+ \__prg_break_point:
+ }
+ }
}
-\cs_new:Npn \__fp_array_to_clist_i:wwww #1; #2 \s__fp #3; #4 @
+\cs_new:Npx \__fp_array_to_clist_loop:Nw #1#2;
{
- #2
- \exp_after:wN \__fp_array_to_clist_i:wwww
- \tex_romannumeral:D -`0 \__fp_to_tl:w \s__fp #3 ; ;
- #4 , ~ #1 @
+ \exp_not:N \use_none:n #1
+ \exp_not:N \exp_after:wN
+ {
+ \exp_not:N \exp_after:wN ,
+ \exp_not:N \exp_after:wN \c_space_tl
+ \exp_not:N \tex_romannumeral:D -`0
+ \exp_not:N \__fp_to_tl_dispatch:w #1 #2 ;
+ }
+ \exp_not:N \__fp_array_to_clist_loop:Nw
}
-\cs_new:Npn \__fp_array_to_clist_ii:ww #1 ; , ~ , ~ #2 @ #3 \s_stop {#2}
%%
%% File: l3fp-assign.dtx Copyright (C) 2011-2012 The LaTeX3 project
%%
@@ -4555,8 +4580,18 @@
{ \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_o:w }
\cs_new_protected_nopar:Npn \fp_gabs:N { \__fp_abs:NNN \tl_gset:Nx \__fp_abs_o:w }
-\cs_new_protected_nopar:Npn \fp_neg:N { \__fp_abs:NNN \tl_set:Nx \__fp_neg_o:w }
-\cs_new_protected_nopar:Npn \fp_gneg:N { \__fp_abs:NNN \tl_gset:Nx \__fp_neg_o:w }
+\cs_new_protected_nopar:Npx \fp_neg:N
+ {
+ \exp_not:N \__fp_abs:NNN
+ \exp_not:N \tl_set:Nx
+ \exp_not:c { __fp_-_o:w }
+ }
+\cs_new_protected_nopar:Npx \fp_gneg:N
+ {
+ \exp_not:N \__fp_abs:NNN
+ \exp_not:N \tl_gset:Nx
+ \exp_not:c { __fp_-_o: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 }