summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx
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/source/latex/l3kernel/l3fp-convert.dtx
parente5a6b18348ead0cec45f680a2bacf024120cfdec (diff)
latex3
git-svn-id: svn://tug.org/texlive/trunk@27600 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.dtx103
1 files changed, 64 insertions, 39 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx b/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx
index 0135da6304b..52fda439459 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3fp-convert.dtx
@@ -36,7 +36,7 @@
%
%<*driver>
\RequirePackage{l3bootstrap}
-\GetIdInfo$Id: l3fp-convert.dtx 4129 2012-08-20 20:38:28Z mittelba $
+\GetIdInfo$Id: l3fp-convert.dtx 4180 2012-08-31 16:44:34Z bruno $
{L3 Floating-point conversion}
\documentclass[full]{l3doc}
\begin{document}
@@ -82,7 +82,7 @@
%
% \subsection{Trimming trailing zeros}
%
-% \begin{macro}[int, EXP]{\@@_trim_zeros:w}
+% \begin{macro}[aux, EXP]{\@@_trim_zeros:w}
% \begin{macro}[aux, EXP]
% {\@@_trim_zeros_loop:w, \@@_trim_zeros_dot:w, \@@_trim_zeros_end:w}
% If |#1| ends with a $0$, the \texttt{loop} auxiliary takes that zero
@@ -109,13 +109,14 @@
% \begin{macro}[EXP]
% {\fp_to_scientific:N, \fp_to_scientific:c, \fp_to_scientific:n}
% The three public functions evaluate their argument, then pass it to
-% \cs{@@_to_scientific:w}.
+% \cs{@@_to_scientific_dispatch:w}.
% \begin{macrocode}
-\cs_new:Npn \fp_to_scientific:N #1 { \exp_after:wN \@@_to_scientific:w #1 }
+\cs_new:Npn \fp_to_scientific:N #1
+ { \exp_after:wN \@@_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 \@@_to_scientific:w
+ \exp_after:wN \@@_to_scientific_dispatch:w
\tex_romannumeral:D -`0 \@@_parse:n
}
% \end{macrocode}
@@ -123,7 +124,7 @@
%
% \begin{macro}[aux, EXP]
% {
-% \@@_to_scientific:w,
+% \@@_to_scientific_dispatch:w,
% \@@_to_scientific_normal:wnnnnn,
% \@@_to_scientific_normal:wNw
% }
@@ -147,7 +148,7 @@
\tl_to_lowercase:n
{
\group_end:
- \cs_new:Npn \@@_to_scientific:w \s_@@ \@@_chk:w #1#2
+ \cs_new:Npn \@@_to_scientific_dispatch:w \s_@@ \@@_chk:w #1#2
{
\if_meaning:w 2 #2 \exp_after:wN - \tex_romannumeral:D -`0 \fi:
\if_case:w #1 \exp_stop_f:
@@ -196,14 +197,16 @@
%
% \begin{macro}[EXP]
% {\fp_to_decimal:N, \fp_to_decimal:c, \fp_to_decimal:n}
-% All three public variants are based on the same \cs{@@_to_decimal:w}
+% All three public variants are based on the same
+% \cs{@@_to_decimal_dispatch:w}
% after evaluating their argument to an internal floating point.
% \begin{macrocode}
-\cs_new:Npn \fp_to_decimal:N #1 { \exp_after:wN \@@_to_decimal:w #1 }
+\cs_new:Npn \fp_to_decimal:N #1
+ { \exp_after:wN \@@_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 \@@_to_decimal:w
+ \exp_after:wN \@@_to_decimal_dispatch:w
\tex_romannumeral:D -`0 \@@_parse:n
}
% \end{macrocode}
@@ -211,12 +214,13 @@
%
% \begin{macro}[aux, EXP]
% {
-% \@@_to_decimal:w,
+% \@@_to_decimal_dispatch:w,
% \@@_to_decimal_normal:wnnnnn,
% \@@_to_decimal_large:Nnnw,
% \@@_to_decimal_huge:wnnnn,
% }
-% The structure is similar to \cs{@@_to_scientific:w}. Insert |-| for
+% The structure is similar to \cs{@@_to_scientific_dispatch:w}.
+% Insert |-| for
% negative numbers. Zero gives $0$, $\pm\infty$ and \nan{} yield an
% \enquote{invalid operation} exception; note that $\pm\infty$
% produces a very large output, which we don't expand now since it
@@ -229,7 +233,7 @@
% non-positive, the result should be $0.\meta{zeros}\meta{digits}$,
% trimmed.
% \begin{macrocode}
-\cs_new:Npn \@@_to_decimal:w \s_@@ \@@_chk:w #1#2
+\cs_new:Npn \@@_to_decimal_dispatch:w \s_@@ \@@_chk:w #1#2
{
\if_meaning:w 2 #2 \exp_after:wN - \tex_romannumeral:D -`0 \fi:
\if_case:w #1 \exp_stop_f:
@@ -297,26 +301,26 @@
%
% \begin{macro}[EXP]{\fp_to_tl:N, \fp_to_tl:c, \fp_to_tl:n}
% These three public functions evaluate their argument, then pass it
-% to \cs{@@_to_tl:w}.
+% to \cs{@@_to_tl_dispatch:w}.
% \begin{macrocode}
-\cs_new:Npn \fp_to_tl:N #1 { \exp_after:wN \@@_to_tl:w #1 }
+\cs_new:Npn \fp_to_tl:N #1 { \exp_after:wN \@@_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 \@@_to_tl:w
+ \exp_after:wN \@@_to_tl_dispatch:w
\tex_romannumeral:D -`0 \@@_parse:n
}
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}[aux, EXP]{\@@_to_tl:w, \@@_to_tl_normal:nnnnn}
-% A structure similar to \cs{@@_to_scientific:w} and
-% \cs{@@_to_decimal:w}, but without the \enquote{invalid operation}
+% \begin{macro}[aux, EXP]{\@@_to_tl_dispatch:w, \@@_to_tl_normal:nnnnn}
+% A structure similar to \cs{@@_to_scientific_dispatch:w} and
+% \cs{@@_to_decimal_dispatch:w}, but without the \enquote{invalid operation}
% exception. First filter special cases. We express normal numbers
% in decimal notation if the exponent is in the range $[-2,16]$, and
% otherwise use scientific notation.
% \begin{macrocode}
-\cs_new:Npn \@@_to_tl:w \s_@@ \@@_chk:w #1#2
+\cs_new:Npn \@@_to_tl_dispatch:w \s_@@ \@@_chk:w #1#2
{
\if_meaning:w 2 #2 \exp_after:wN - \tex_romannumeral:D -`0 \fi:
\if_case:w #1 \exp_stop_f:
@@ -367,27 +371,27 @@
%
% \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:w}.
+% to \cs{fp_to_int_dispatch:w}.
% \begin{macrocode}
-\cs_new:Npn \fp_to_int:N #1 { \exp_after:wN \@@_to_int:w #1 }
+\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 }
\cs_new_nopar:Npn \fp_to_int:n
{
- \exp_after:wN \@@_to_int:w
+ \exp_after:wN \@@_to_int_dispatch:w
\tex_romannumeral:D -`0 \@@_parse:n
}
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}[aux, EXP]{\@@_to_int:w}
+% \begin{macro}[aux, 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:w} is such that there will be no
+% definition of \cs{@@_to_decimal_dispatch:w} is such that there will be no
% trailing dot nor zero.
% \begin{macrocode}
-\cs_new:Npn \@@_to_int:w #1;
+\cs_new:Npn \@@_to_int_dispatch:w #1;
{
- \exp_after:wN \@@_to_decimal:w \tex_romannumeral:D -`0
+ \exp_after:wN \@@_to_decimal_dispatch:w \tex_romannumeral:D -`0
\@@_round:Nwn \@@_round_to_nearest:NNN #1; { 0 }
}
% \end{macrocode}
@@ -472,24 +476,45 @@
% \subsection{Convert an array of floating points to a comma list}
%
% \begin{macro}[int, EXP]{\@@_array_to_clist:n}
-% \begin{macro}[aux, EXP]{\@@_array_to_clist_i:wwww, \@@_array_to_clist_ii:ww}
-% Converts an array of floating point numbers to a comma-list.
+% \begin{macro}[aux, EXP]{\@@_array_to_clist_loop:Nw}
+% Converts an array of floating point numbers to a comma-list. If
+% speed here ends up irrelevant, we can simplify the code for the
+% auxiliary to become
+% \begin{verbatim}
+% \cs_new:Npn \__fp_array_to_clist_loop:Nw #1#2;
+% {
+% \use_none:n #1
+% { , ~ } \fp_to_tl:n { #1 #2 ; }
+% \__fp_array_to_clist_loop:Nw
+% }
+% \end{verbatim}
+% The \cs{use_ii:nn} function is expanded after \cs{@@_expand:n} is
+% done, and it removes |,~| from the start of the representation.
% \begin{macrocode}
\cs_new:Npn \@@_array_to_clist:n #1
{
- \@@_array_to_clist_i:wwww ;
- #1
- \@@_array_to_clist_ii:ww \s_@@ ; @
- ; , ~ , ~ @ \s_stop
+ \tl_if_empty:nF {#1}
+ {
+ \@@_expand:n
+ {
+ { \use_ii:nn }
+ \@@_array_to_clist_loop:Nw #1 { ? \__prg_break: } ;
+ \__prg_break_point:
+ }
+ }
}
-\cs_new:Npn \@@_array_to_clist_i:wwww #1; #2 \s_@@ #3; #4 @
+\cs_new:Npx \@@_array_to_clist_loop:Nw #1#2;
{
- #2
- \exp_after:wN \@@_array_to_clist_i:wwww
- \tex_romannumeral:D -`0 \@@_to_tl:w \s_@@ #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 \@@_to_tl_dispatch:w #1 #2 ;
+ }
+ \exp_not:N \@@_array_to_clist_loop:Nw
}
-\cs_new:Npn \@@_array_to_clist_ii:ww #1 ; , ~ , ~ #2 @ #3 \s_stop {#2}
% \end{macrocode}
% \end{macro}
% \end{macro}