summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str-format.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3experimental/l3str/l3str-format.sty')
-rw-r--r--Master/texmf-dist/tex/latex/l3experimental/l3str/l3str-format.sty153
1 files changed, 79 insertions, 74 deletions
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str-format.sty b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str-format.sty
index 554ebefd793..caa70c099ae 100644
--- a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str-format.sty
+++ b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str-format.sty
@@ -20,7 +20,7 @@
%%
%% File: l3str-format.dtx
\RequirePackage{expl3}
-\ProvidesExplPackage{l3str-format}{2019-07-01}{}
+\ProvidesExplPackage{l3str-format}{2019-08-25}{}
{L3 Experimental string formatting}
\cs_generate_variant:Nn \use:nn { nf }
\cs_generate_variant:Nn \use:nnn { fnf }
@@ -286,23 +286,23 @@
{#3} #5
}
\cs_new:Npn \fp_format:nn #1
- { \exp_args:Nf \__str_format_fp:nn { \__fp_parse:n {#1} } }
+ { \exp_args:Nf \__str_format_fp:nn { \fp_to_tl:n {#1} } }
\cs_new:Npn \__str_format_fp:nn #1#2
{
\tl_to_str:f
{
- \exp_last_unbraced:Nf \__str_format_fp:NNNnnNw
+ \exp_last_unbraced:Nf \__str_format_fp:NNNnnNn
{ \__str_format_parse:n {#2} }
- #1
+ {#1}
}
}
-\cs_new:Npn \__str_format_fp:NNNnnNw
- #1#2#3#4#5#6 \s__fp \__fp_chk:w #7 #8
+\cs_new:Npn \__str_format_fp:NNNnnNn
+ #1#2#3#4#5#6#7
{
\token_if_eq_charcode:NNTF #2 ?
{ \__str_format_put:nw { #1 > } }
{ \__str_format_put:nw { #1 #2 } }
- \token_if_eq_meaning:NNTF 2 #8
+ \tl_if_head_eq_charcode:nNTF {#7} -
{ \__str_format_put:nw { - } }
{
\str_case:nnF {#3}
@@ -314,123 +314,128 @@
}
\__str_format_put:nw { {#4} }
\tl_if_empty:nTF {#5}
- { \__str_format_put:nw { { 6} } }
+ {
+ \token_if_eq_meaning:NNTF #6 ?
+ { \__str_format_put:nw { { } } }
+ { \__str_format_put:nw { { 6} } }
+ }
{ \__str_format_put:nw { {#5} } }
\str_case:nnF {#6}
{
- { e } { \__str_format_fp:wnnnNNw \__str_format_fp_e:wn }
- { f } { \__str_format_fp:wnnnNNw \__str_format_fp_f:wn }
- { g } { \__str_format_fp:wnnnNNw \__str_format_fp_g:wn }
- { ? } { \__str_format_fp:wnnnNNw \__str_format_fp_g:wn }
+ { e } { \__str_format_fp:wnnnNNn \__str_format_fp_e:nn }
+ { f } { \__str_format_fp:wnnnNNn \__str_format_fp_f:nn }
+ { g } { \__str_format_fp:wnnnNNn \__str_format_fp_g:nn }
+ { ? } { \__str_format_fp:wnnnNNn \__str_format_fp_g:nn }
}
{
\__kernel_msg_expandable_error:nnnn
{ str } { invalid-style-format } {#6} { fp }
- \__str_format_fp:wnnnNNw \__str_format_fp_g:wn
+ \__str_format_fp:wnnnNNn \__str_format_fp_g:nn
}
- \s_stop
- \s__fp \__fp_chk:w #7 #8
+ \s_stop {#7}
}
-\cs_new:Npn \__str_format_fp:wnnnNNw
- #1 \s_stop #2 #3 #4 #5#6 #7 ;
+\cs_new:Npn \__str_format_fp:wnnnNNn
+ #1 \s_stop #2 #3 #4 #5#6 #7
{
\exp_args:Nc \exp_args:Nf
{ __str_format_align_#6:nnnN }
- { #1 #7 ; {#2} }
+ { #1 {#7} {#2} }
{#4}
{#3} #5
}
-\cs_new:Npn \__str_format_fp_round:wn #1 ; #2
- { \__fp_parse:n { round ( #1; , #2 - \__fp_exponent:w #1; ) } }
-\cs_new:Npn \__str_format_fp_e:wn \s__fp \__fp_chk:w #1#2#3 ; #4
+\cs_new:Npn \__str_format_fp_round:nn #1 #2
+ { \fp_to_tl:n { abs ( round ( #1 , #2 - logb(#1) - 1 ) ) } }
+\cs_new:Npn \__str_format_fp_e:nn #1#2
+ {
+ \exp_args:Nf \__str_format_fp_e_aux:nn
+ { \__str_format_fp_round:nn {#1} { #2 + 1 } }
+ {#2}
+ }
+\cs_new:Npn \__str_format_fp_e_aux:nn #1#2
{
- \int_case:nnF {#1}
+ \str_case:nnF {#1}
{
- { 0 } { \use:nf { 0 . } { \prg_replicate:nn {#4} { 0 } } e 0 }
- { 2 } { inf }
- { 3 } { nan }
+ { inf } { inf }
+ { nan } { nan }
}
{
- \exp_last_unbraced:Nf \__str_format_fp_e_aux:wn
- { \__str_format_fp_round:wn \s__fp \__fp_chk:w #1#2#3 ; { #4 + 1 } }
- {#4}
+ \exp_last_unbraced:Nf \__str_format_fp_e_aux:wwn
+ { \fp_to_scientific:n {#1} } ;
+ {#2}
}
}
-\cs_new:Npn \__str_format_fp_e_aux:wn
- \s__fp \__fp_chk:w #1#2 #3 #4#5#6#7 ; #8
+\cs_new:Npn \__str_format_fp_e_aux:wwn #1 . #2 e #3 ; #4
{
- \__str_format_put:fw { \int_eval:n { #3 - 1 } }
- \__str_format_put:nw { e }
- \int_compare:nNnTF {#8} > \c__fp_prec_int
+ \__str_format_put:nw { e #3 }
+ \int_compare:nNnTF {#4} < \c__fp_prec_int
{
- \__str_format_put:fw { \prg_replicate:nn { #8 - \c__fp_prec_int + 1 } {0} }
- \__str_format_put:fw { \use_none:n #4#5#6#7 }
+ \__str_format_put:fw { \str_range:nnn { #2 } { 1 } { #4 } }
+ \__str_format_put:nw { #1 . }
}
{
\__str_format_put:fw
- { \str_range:nnn { #4#5#6#7 0 } { 2 } { #8 + 1 } }
+ { \prg_replicate:nn { #4 - \c__fp_prec_int + 1 } { 0 } }
+ \__str_format_put:nw { #1 . #2 }
}
- \__str_format_put:fw { \use_i:nnnn #4 . }
\use_none:n \s_stop
}
-\cs_new:Npn \__str_format_fp_f:wn \s__fp \__fp_chk:w #1#2#3 ; #4
+\cs_new:Npn \__str_format_fp_f:nn #1#2
+ {
+ \exp_args:Nf \__str_format_fp_f_aux:nn
+ { \fp_to_tl:n { abs ( round ( #1 , #2 ) ) } }
+ {#2}
+ }
+\cs_new:Npn \__str_format_fp_f_aux:nn #1#2
{
- \int_case:nnF {#1}
+ \str_case:nnF {#1}
{
- {0} { \use:nf { 0 . } { \prg_replicate:nn {#4} { 0 } } }
- {2} { inf }
- {3} { nan }
+ { inf } { inf }
+ { nan } { nan }
}
{
\exp_last_unbraced:Nf \__str_format_fp_f_aux:wwwn
- {
- \fp_to_decimal:n
- { abs ( round ( \s__fp \__fp_chk:w #1#2#3 ; , #4 ) ) }
- }
- . . ;
- {#4}
+ { \fp_to_decimal:n {#1} } . . ; {#2}
}
}
\cs_new:Npn \__str_format_fp_f_aux:wwwn #1 . #2 . #3 ; #4
{
- \use:nf
- { #1 . #2 }
+ \use:nf { #1 . #2 }
{ \prg_replicate:nn { #4 - \__str_count:n {#2} } {0} }
}
-\cs_new:Npn \__str_format_fp_g:wn \s__fp \__fp_chk:w #1#2 ; #3
+\cs_new:Npn \__str_format_fp_g:nn #1#2
{
- \int_case:nnF {#1}
+ \tl_if_empty:nTF {#2} { \fp_to_tl:n { abs(#1) } }
{
- {0} { 0 }
- {2} { inf }
- {3} { nan }
- }
- {
- \exp_last_unbraced:Nf \__str_format_fp_g_aux:wn
- {
- \__str_format_fp_round:wn \s__fp \__fp_chk:w #1#2 ;
- { \int_max:nn {1} {#3} }
- }
- { \int_max:nn {1} {#3} }
+ \exp_args:Nf \__str_format_fp_g_aux:nn
+ { \__str_format_fp_round:nn {#1} { \int_max:nn {1} {#2} } }
+ { \int_max:nn {1} {#2} }
}
}
-\cs_new:Npn \__str_format_fp_g_aux:wn #1; #2
+\cs_new:Npn \__str_format_fp_g_aux:nn #1#2
{
- \int_compare:nNnTF { \__fp_exponent:w #1; } < { -3 }
- { \__str_format_to_scientific:n }
+ \str_case:nnF {#1}
+ {
+ { 0 } { 0 }
+ { inf } { inf }
+ { nan } { nan }
+ }
{
- \int_compare:nNnTF { \__fp_exponent:w #1; } > {#2}
- { \__str_format_to_scientific:n }
- { \fp_to_decimal:n }
+ \fp_compare:nTF { 1e-4 <= #1 < 1e#2 }
+ { \fp_to_decimal:n {#1} }
+ {
+ \exp_last_unbraced:Nf \__str_format_fp_trim:w
+ { \fp_to_scientific:n {#1} }
+ }
}
- { \__fp_set_sign_o:w 0 #1; @ \prg_do_nothing: }
}
-\cs_new:Npn \__str_format_to_scientific:n
+\cs_new:Npn \__str_format_fp_trim:w #1 e
{
- \exp_after:wN \__str_format_fp_trim:w
- \exp:w \exp_end_continue_f:w \fp_to_scientific:n
+ \__str_format_fp_trim_loop:w #1
+ ; \__str_format_fp_trim_loop:w 0; \__str_format_fp_trim_dot:w .; \s_stop e
}
-\cs_new:Npn \__str_format_fp_trim:w #1 e { \__fp_trim_zeros:w #1 ; e }
+\cs_new:Npn \__str_format_fp_trim_loop:w #1 0; #2 { #2 #1 ; #2 }
+\cs_new:Npn \__str_format_fp_trim_dot:w #1 .; { \__str_format_fp_trim_end:w #1 ; }
+\cs_new:Npn \__str_format_fp_trim_end:w #1 ; #2 \s_stop { #1 }
\__kernel_msg_new:nnn { str } { invalid-format }
{ Invalid~format~'#1'. }
\__kernel_msg_new:nnn { str } { invalid-align-format }