summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-02-23 21:54:14 +0000
committerKarl Berry <karl@freefriends.org>2018-02-23 21:54:14 +0000
commit87d871a3d83784d48b71fa3712b9f525bfc710d2 (patch)
treef12f9ffdc697b5af9ee14c06874ec0e2f72c9f94 /Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx
parentccc63194ce7813106830c8a8755c54d89de831b4 (diff)
l3 (22feb18)
git-svn-id: svn://tug.org/texlive/trunk@46720 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx')
-rw-r--r--Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx163
1 files changed, 135 insertions, 28 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx b/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx
index c727afc5696..abf02162559 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-%% File: l3fp-convert.dtx Copyright(C) 2011-2017 The LaTeX3 Project
+%% File: l3fp-convert.dtx Copyright(C) 2011-2018 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
@@ -41,7 +41,7 @@
% }^^A
% }
%
-% \date{Released 2017/12/16}
+% \date{Released 2018/02/21}
%
% \maketitle
%
@@ -61,6 +61,39 @@
%<@@=fp>
% \end{macrocode}
%
+% \subsection{Dealing with tuples}
+%
+% \begin{macro}[EXP]
+% {\@@_tuple_convert:Nw, \@@_tuple_convert_loop:nNw, \@@_tuple_convert_end:w}
+% The first argument is for instance \cs{@@_to_tl_dispatch:w}, which
+% converts any floating point object to the appropriate
+% representation. We loop through all items, putting |,~| between all
+% of them and making sure to remove the leading |,~|.
+% \begin{macrocode}
+\cs_new:Npn \@@_tuple_convert:Nw #1 \s_@@_tuple \@@_tuple_chk:w #2 ;
+ {
+ \int_case:nnF { \@@_array_count:n {#2} }
+ {
+ { 0 } { ( ) }
+ { 1 } { \@@_tuple_convert_end:w @ { #1 #2 , } }
+ }
+ {
+ \@@_tuple_convert_loop:nNw { } #1
+ #2 { ? \@@_tuple_convert_end:w } ;
+ @ { \use_none:nn }
+ }
+ }
+\cs_new:Npn \@@_tuple_convert_loop:nNw #1#2#3#4; #5 @ #6
+ {
+ \use_none:n #3
+ \exp_args:Nf \@@_tuple_convert_loop:nNw { #2 #3#4 ; } #2 #5
+ @ { #6 , ~ #1 }
+ }
+\cs_new:Npn \@@_tuple_convert_end:w #1 @ #2
+ { \exp_after:wN ( \exp:w \exp_end_continue_f:w #2 ) }
+% \end{macrocode}
+% \end{macro}
+%
% \subsection{Trimming trailing zeros}
%
% \begin{macro}[EXP]{\@@_trim_zeros:w}
@@ -104,8 +137,28 @@
% \end{macro}
%
% \begin{macro}[EXP]
+% {\@@_to_scientific_dispatch:w, \@@_to_scientific_recover:w, \@@_tuple_to_scientific:w}
+% We allow tuples.
+% \begin{macrocode}
+\cs_new:Npn \@@_to_scientific_dispatch:w #1
+ {
+ \@@_change_func_type:NNN
+ #1 \@@_to_scientific:w \@@_to_scientific_recover:w
+ #1
+ }
+\cs_new:Npn \@@_to_scientific_recover:w #1 #2 ;
+ {
+ \@@_error:nffn { fp-unknown-type } { \tl_to_str:n { #2 ; } } { } { }
+ nan
+ }
+\cs_new:Npn \@@_tuple_to_scientific:w
+ { \@@_tuple_convert:Nw \@@_to_scientific_dispatch:w }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]
% {
-% \@@_to_scientific_dispatch:w,
+% \@@_to_scientific:w,
% \@@_to_scientific_normal:wnnnnn,
% \@@_to_scientific_normal:wNw
% }
@@ -122,7 +175,7 @@
% second step grab the first digit (previously hidden in braces) to
% order the various parts correctly.
% \begin{macrocode}
-\cs_new:Npn \@@_to_scientific_dispatch:w \s_@@ \@@_chk:w #1#2
+\cs_new:Npn \@@_to_scientific:w \s_@@ \@@_chk:w #1#2
{
\if_meaning:w 2 #2 \exp_after:wN - \exp:w \exp_end_continue_f:w \fi:
\if_case:w #1 \exp_stop_f:
@@ -178,13 +231,33 @@
% \end{macro}
%
% \begin{macro}[EXP]
+% {\@@_to_decimal_dispatch:w, \@@_to_decimal_recover:w, \@@_tuple_to_decimal:w}
+% We allow tuples.
+% \begin{macrocode}
+\cs_new:Npn \@@_to_decimal_dispatch:w #1
+ {
+ \@@_change_func_type:NNN
+ #1 \@@_to_decimal:w \@@_to_decimal_recover:w
+ #1
+ }
+\cs_new:Npn \@@_to_decimal_recover:w #1 #2 ;
+ {
+ \@@_error:nffn { fp-unknown-type } { \tl_to_str:n { #2 ; } } { } { }
+ nan
+ }
+\cs_new:Npn \@@_tuple_to_decimal:w
+ { \@@_tuple_convert:Nw \@@_to_decimal_dispatch:w }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]
% {
-% \@@_to_decimal_dispatch:w,
+% \@@_to_decimal:w,
% \@@_to_decimal_normal:wnnnnn,
% \@@_to_decimal_large:Nnnw,
% \@@_to_decimal_huge:wnnnn,
% }
-% The structure is similar to \cs{@@_to_scientific_dispatch:w}.
+% The structure is similar to \cs{@@_to_scientific:w}.
% Insert |-| for
% negative numbers. Zero gives $0$, $\pm\infty$ and \nan{} yield an
% \enquote{invalid operation} exception; note that $\pm\infty$
@@ -198,7 +271,7 @@
% non-positive, the result should be $0.\meta{zeros}\meta{digits}$,
% trimmed.
% \begin{macrocode}
-\cs_new:Npn \@@_to_decimal_dispatch:w \s_@@ \@@_chk:w #1#2
+\cs_new:Npn \@@_to_decimal:w \s_@@ \@@_chk:w #1#2
{
\if_meaning:w 2 #2 \exp_after:wN - \exp:w \exp_end_continue_f:w \fi:
\if_case:w #1 \exp_stop_f:
@@ -275,9 +348,24 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}[EXP]{\@@_to_tl_dispatch:w, \@@_to_tl_recover:w, \@@_tuple_to_tl:w}
+% We allow tuples.
+% \begin{macrocode}
+\cs_new:Npn \@@_to_tl_dispatch:w #1
+ { \@@_change_func_type:NNN #1 \@@_to_tl:w \@@_to_tl_recover:w #1 }
+\cs_new:Npn \@@_to_tl_recover:w #1 #2 ;
+ {
+ \@@_error:nffn { fp-unknown-type } { \tl_to_str:n { #2 ; } } { } { }
+ nan
+ }
+\cs_new:Npn \@@_tuple_to_tl:w
+ { \@@_tuple_convert:Nw \@@_to_tl_dispatch:w }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}[EXP]
% {
-% \@@_to_tl_dispatch:w, \@@_to_tl_normal:nnnnn,
+% \@@_to_tl:w, \@@_to_tl_normal:nnnnn,
% \@@_to_tl_scientific:wnnnnn, \@@_to_tl_scientific:wNw
% }
% A structure similar to \cs{@@_to_scientific_dispatch:w} and
@@ -286,7 +374,7 @@
% in decimal notation if the exponent is in the range $[-2,16]$, and
% otherwise use scientific notation.
% \begin{macrocode}
-\cs_new:Npn \@@_to_tl_dispatch:w \s_@@ \@@_chk:w #1#2
+\cs_new:Npn \@@_to_tl:w \s_@@ \@@_chk:w #1#2
{
\if_meaning:w 2 #2 \exp_after:wN - \exp:w \exp_end_continue_f:w \fi:
\if_case:w #1 \exp_stop_f:
@@ -327,20 +415,40 @@
% \subsection{Convert to dimension or integer}
%
% \begin{macro}[EXP]{\fp_to_dim:N, \fp_to_dim:c, \fp_to_dim:n}
-% These three public functions rely on \cs{fp_to_decimal:n}
-% internally.
+% \begin{macro}[EXP]{\@@_to_dim_dispatch:w, \@@_to_dim_recover:w, \@@_to_dim:w}
+% All three public variants are based on the same
+% \cs{@@_to_dim_dispatch:w} after evaluating their argument to an
+% internal floating point.
+% We only allow floating point numbers, not tuples.
% \begin{macrocode}
\cs_new:Npn \fp_to_dim:N #1
- { \fp_to_decimal:N #1 pt }
+ { \exp_after:wN \@@_to_dim_dispatch:w #1 }
\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_dim:n
+ {
+ \exp_after:wN \@@_to_dim_dispatch:w
+ \exp:w \exp_end_continue_f:w \@@_parse:n
+ }
+\cs_new:Npn \@@_to_dim_dispatch:w #1#2 ;
+ {
+ \@@_change_func_type:NNN #1 \@@_to_dim:w \@@_to_dim_recover:w
+ #1 #2 ;
+ }
+\cs_new:Npn \@@_to_dim_recover:w #1
+ { \@@_invalid_operation:nnw { 0pt } { fp_to_dim } }
+\cs_new:Npn \@@_to_dim:w #1 ; { \@@_to_decimal:w #1 ; pt }
% \end{macrocode}
% \end{macro}
+% \end{macro}
%
% \begin{macro}[EXP]{\fp_to_int:N, \fp_to_int:c, \fp_to_int:n}
-% These three public functions evaluate their argument, then pass it
-% to \cs{fp_to_int_dispatch:w}.
+% \begin{macro}[EXP]{\@@_to_int_dispatch:w, \@@_to_int_recover:w}
+% For the most part identical to \cs{fp_to_dim:N} but without |pt|,
+% and where \cs{@@_to_int:w} does more work.
+% To convert to an integer, first round to $0$ places (to the nearest
+% integer), then express the result as a decimal number: the
+% definition of \cs{@@_to_decimal_dispatch:w} is such that there are no
+% trailing dot nor zero.
% \begin{macrocode}
\cs_new:Npn \fp_to_int:N #1 { \exp_after:wN \@@_to_int_dispatch:w #1 }
\cs_generate_variant:Nn \fp_to_int:N { c }
@@ -349,22 +457,21 @@
\exp_after:wN \@@_to_int_dispatch:w
\exp:w \exp_end_continue_f:w \@@_parse:n
}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}[EXP]{\@@_to_int_dispatch:w}
-% To convert to an integer, first round to $0$ places (to the nearest
-% integer), then express the result as a decimal number: the
-% definition of \cs{@@_to_decimal_dispatch:w} is such that there are no
-% trailing dot nor zero.
-% \begin{macrocode}
-\cs_new:Npn \@@_to_int_dispatch:w #1;
+\cs_new:Npn \@@_to_int_dispatch:w #1#2 ;
{
- \exp_after:wN \@@_to_decimal_dispatch:w \exp:w \exp_end_continue_f:w
+ \@@_change_func_type:NNN #1 \@@_to_int:w \@@_to_int_recover:w
+ #1 #2 ;
+ }
+\cs_new:Npn \@@_to_int_recover:w #1
+ { \@@_invalid_operation:nnw { 0 } { fp_to_int } }
+\cs_new:Npn \@@_to_int:w #1;
+ {
+ \exp_after:wN \@@_to_decimal:w \exp:w \exp_end_continue_f:w
\@@_round:Nwn \@@_round_to_nearest:NNN #1; { 0 }
}
% \end{macrocode}
% \end{macro}
+% \end{macro}
%
% \subsection{Convert from a dimension}
%
@@ -390,7 +497,7 @@
% performed by \cs{@@_mul_npos_o:Nww}, and cancelled by
% \cs{prg_do_nothing:} here.
% \begin{macrocode}
-\__debug_patch_args:nNNpn { { (#1) } }
+\__kernel_patch_args:nNNpn { { (#1) } }
\cs_new:Npn \dim_to_fp:n #1
{
\exp_after:wN \@@_from_dim_test:ww