[latex3-commits] [l3svn] r6883 - Make \fp_to_scientific:n adhere to its documentation (fixes #258)

noreply at latex-project.org noreply at latex-project.org
Sat Feb 11 05:07:05 CET 2017


Author: bruno
Date: 2017-02-11 05:07:04 +0100 (Sat, 11 Feb 2017)
New Revision: 6883

Modified:
   trunk/l3kernel/l3fp-convert.dtx
   trunk/l3kernel/l3fp.dtx
   trunk/l3kernel/testfiles/m3expl001.luatex.tlg
   trunk/l3kernel/testfiles/m3expl001.ptex.tlg
   trunk/l3kernel/testfiles/m3expl001.tlg
   trunk/l3kernel/testfiles/m3expl001.uptex.tlg
   trunk/l3kernel/testfiles/m3expl001.xetex.tlg
   trunk/l3kernel/testfiles/m3expl003.luatex.tlg
   trunk/l3kernel/testfiles/m3expl003.ptex.tlg
   trunk/l3kernel/testfiles/m3expl003.tlg
   trunk/l3kernel/testfiles/m3expl003.uptex.tlg
   trunk/l3kernel/testfiles/m3expl003.xetex.tlg
   trunk/l3kernel/testfiles/m3fp-convert002.tlg
   trunk/l3kernel/testfiles/m3fp-convert003.tlg
Log:
Make \fp_to_scientific:n adhere to its documentation (fixes #258)

Now it gives things like 0.000000000000000e0 or -1.234500000000000e-321


Modified: trunk/l3kernel/l3fp-convert.dtx
===================================================================
--- trunk/l3kernel/l3fp-convert.dtx	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/l3fp-convert.dtx	2017-02-11 04:07:04 UTC (rev 6883)
@@ -124,22 +124,21 @@
 %   \enquote{invalid_operation} exception.  In the normal case,
 %   decrement the exponent and unbrace the $4$ brace groups, then in a
 %   second step grab the first digit (previously hidden in braces) to
-%   order the various parts correctly.  Finally trim zeros.
+%   order the various parts correctly.
 %    \begin{macrocode}
 \cs_new:Npn \@@_to_scientific_dispatch: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:
-         \@@_case_return:nw { 0 }
+         \@@_case_return:nw { 0.000000000000000e0 }
     \or: \exp_after:wN \@@_to_scientific_normal:wnnnnn
     \or:
       \@@_case_use:nw
         {
-          \@@_invalid_operation:nnw
+          \exp_args:Nf \@@_invalid_operation:nnw
             {
-              \exp_after:wN 1
-              \exp_after:wN e
-              \int_use:N \c_@@_max_exponent_int
+              \@@_expand:n
+                { { 1.000000000000000e } \int_use:N \c_@@_max_exponent_int }
             }
             { fp_to_scientific }
         }
@@ -147,7 +146,7 @@
       \@@_case_use:nw
         {
           \@@_invalid_operation:nnw
-            { 0 }
+            { 0.000000000000000e0 }
             { fp_to_scientific }
         }
     \fi:
@@ -156,17 +155,13 @@
 \cs_new:Npn \@@_to_scientific_normal:wnnnnn
   \s_@@ \@@_chk:w 1 #1 #2 #3#4#5#6 ;
   {
-    \if_int_compare:w #2 = \c_one
-      \exp_after:wN \@@_to_scientific_normal:wNw
-    \else:
-      \exp_after:wN \@@_to_scientific_normal:wNw
-      \exp_after:wN e
-      \__int_value:w \__int_eval:w #2 - \c_one
-    \fi:
+    \exp_after:wN \@@_to_scientific_normal:wNw
+    \exp_after:wN e
+    \__int_value:w \__int_eval:w #2 - \c_one
     ; #3 #4 #5 #6 ;
   }
 \cs_new:Npn \@@_to_scientific_normal:wNw #1 ; #2#3;
-  { \@@_trim_zeros:w #2.#3 ; #1 }
+  { #2.#3 #1 }
 %    \end{macrocode}
 % \end{macro}
 %
@@ -290,7 +285,11 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[aux, EXP]{\@@_to_tl_dispatch:w, \@@_to_tl_normal:nnnnn}
+% \begin{macro}[aux, EXP]
+%   {
+%     \@@_to_tl_dispatch:w, \@@_to_tl_normal:nnnnn,
+%     \@@_to_tl_scientific:wnnnnn, \@@_to_tl_scientific:wNw
+%   }
 %   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
@@ -310,11 +309,11 @@
 \cs_new:Npn \@@_to_tl_normal:nnnnn #1
   {
     \if_int_compare:w #1 > \c_sixteen
-      \exp_after:wN \@@_to_scientific_normal:wnnnnn
+      \exp_after:wN \@@_to_tl_scientific:wnnnnn
     \else:
       \if_int_compare:w #1 < - \c_two
         \exp_after:wN \exp_after:wN
-        \exp_after:wN \@@_to_scientific_normal:wnnnnn
+        \exp_after:wN \@@_to_tl_scientific:wnnnnn
       \else:
         \exp_after:wN \exp_after:wN
         \exp_after:wN \@@_to_decimal_normal:wnnnnn
@@ -322,6 +321,16 @@
     \fi:
     \s_@@ \@@_chk:w 1 0 {#1}
   }
+\cs_new:Npn \@@_to_tl_scientific:wnnnnn
+  \s_@@ \@@_chk:w 1 #1 #2 #3#4#5#6 ;
+  {
+    \exp_after:wN \@@_to_tl_scientific:wNw
+    \exp_after:wN e
+    \__int_value:w \__int_eval:w #2 - \c_one
+    ; #3 #4 #5 #6 ;
+  }
+\cs_new:Npn \@@_to_tl_scientific:wNw #1 ; #2#3;
+  { \@@_trim_zeros:w #2.#3 ; #1 }
 %    \end{macrocode}
 % \end{macro}
 %

Modified: trunk/l3kernel/l3fp.dtx
===================================================================
--- trunk/l3kernel/l3fp.dtx	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/l3fp.dtx	2017-02-11 04:07:04 UTC (rev 6883)
@@ -315,7 +315,7 @@
 %   result in (almost) the shortest possible form.  Numbers in the
 %   ranges $(0,10^{-3})$ and $[10^{16},\infty)$ are expressed in
 %   scientific notation with trailing zeros trimmed and no decimal
-%   separator when there is a single significant digit (see
+%   separator when there is a single significant digit (this differs from
 %   \cs{fp_to_scientific:n}).  Numbers in the range $[10^{-3},10^{16})$
 %   are expressed in a decimal notation without exponent, with trailing
 %   zeros trimmed, and no decimal separator for integer values (see

Modified: trunk/l3kernel/testfiles/m3expl001.luatex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.luatex.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl001.luatex.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4104,6 +4104,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3expl001.ptex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.ptex.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl001.ptex.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4092,6 +4092,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3expl001.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl001.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4092,6 +4092,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3expl001.uptex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.uptex.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl001.uptex.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4092,6 +4092,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3expl001.xetex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.xetex.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl001.xetex.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4102,6 +4102,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.luatex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.luatex.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl003.luatex.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4105,6 +4105,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.ptex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.ptex.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl003.ptex.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4093,6 +4093,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl003.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4093,6 +4093,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.uptex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.uptex.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl003.uptex.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4093,6 +4093,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.xetex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.xetex.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3expl003.xetex.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4103,6 +4103,8 @@
 Defining \fp_to_tl:n on line ...
 Defining \__fp_to_tl_dispatch:w on line ...
 Defining \__fp_to_tl_normal:nnnnn on line ...
+Defining \__fp_to_tl_scientific:wnnnnn on line ...
+Defining \__fp_to_tl_scientific:wNw on line ...
 Defining \fp_to_dim:N on line ...
 Defining \fp_to_dim:c on line ...
 Defining \fp_to_dim:n on line ...

Modified: trunk/l3kernel/testfiles/m3fp-convert002.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3fp-convert002.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3fp-convert002.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4,42 +4,42 @@
 ============================================================
 TEST 1: From dimensions
 ============================================================
--3.666671752929688
--1
-0
-1
-1.2e1
-1.23e2
-1.234e3
-1.2345e4
+-3.666671752929688e0
+-1.000000000000000e0
+0.000000000000000e0
+1.000000000000000e0
+1.200000000000000e1
+1.230000000000000e2
+1.234000000000000e3
+1.234500000000000e4
 1.234560000610352e4
 1.234566999816895e4
 1.234567799377441e4
 1.234567889404297e4
 1.234567890930176e4
-2
-0
--2.845260620117188
-1.52587890625e-4
+2.000000000000000e0
+0.000000000000000e0
+-2.845260620117188e0
+1.525878906250000e-4
 ============================================================
 ============================================================
 TEST 2: From dimensions auto convert
 ============================================================
--3.666666666666667
--1
-0
-1
-1.2e1
-1.23e2
-1.234e3
-1.2345e4
-1.23456e4
-1.234567e4
-1.2345678e4
-1.23456789e4
-1.234567891e4
-0
--2.845275590551181
-1.52587890625e-4
-1
+-3.666666666666667e0
+-1.000000000000000e0
+0.000000000000000e0
+1.000000000000000e0
+1.200000000000000e1
+1.230000000000000e2
+1.234000000000000e3
+1.234500000000000e4
+1.234560000000000e4
+1.234567000000000e4
+1.234567800000000e4
+1.234567890000000e4
+1.234567891000000e4
+0.000000000000000e0
+-2.845275590551181e0
+1.525878906250000e-4
+1.000000000000000e0
 ============================================================

Modified: trunk/l3kernel/testfiles/m3fp-convert003.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3fp-convert003.tlg	2017-02-11 03:42:49 UTC (rev 6882)
+++ trunk/l3kernel/testfiles/m3fp-convert003.tlg	2017-02-11 04:07:04 UTC (rev 6883)
@@ -4,34 +4,34 @@
 ============================================================
 TEST 1: fp_to_scientific
 ============================================================
-> \l_tmpa_tl=0.
+> \l_tmpa_tl=0.000000000000000e0.
 <recently read> }
 l. ...  }
-> \l_tmpa_tl=0.
+> \l_tmpa_tl=0.000000000000000e0.
 <recently read> }
 l. ...  }
-> \l_tmpa_tl=1e-2.
+> \l_tmpa_tl=1.000000000000000e-2.
 <recently read> }
 l. ...  }
-> \l_tmpa_tl=1e-2.
+> \l_tmpa_tl=1.000000000000000e-2.
 <recently read> }
 l. ...  }
-> \l_tmpa_tl=1.234e6.
+> \l_tmpa_tl=1.234000000000000e6.
 <recently read> }
 l. ...  }
-> \l_tmpa_tl=1.234e6.
+> \l_tmpa_tl=1.234000000000000e6.
 <recently read> }
 l. ...  }
-> \l_tmpa_tl=1.234e17.
+> \l_tmpa_tl=1.234000000000000e17.
 <recently read> }
 l. ...  }
-> \l_tmpa_tl=1.234e17.
+> \l_tmpa_tl=1.234000000000000e17.
 <recently read> }
 l. ...  }
-> \l_tmpa_tl=-1.2345e-6.
+> \l_tmpa_tl=-1.234500000000000e-6.
 <recently read> }
 l. ...  }
-> \l_tmpa_tl=-1.2345e-6.
+> \l_tmpa_tl=-1.234500000000000e-6.
 <recently read> }
 l. ...  }
 ! Undefined control sequence.
@@ -43,7 +43,7 @@
 misspelled it (e.g., `\hobx'), type `I' and the correct
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
-> \l_tmpa_tl=-1e10000.
+> \l_tmpa_tl=-1.000000000000000e10000.
 <recently read> }
 l. ...  }
 ! Undefined control sequence.
@@ -55,7 +55,7 @@
 misspelled it (e.g., `\hobx'), type `I' and the correct
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
-> \l_tmpa_tl=-1e10000.
+> \l_tmpa_tl=-1.000000000000000e10000.
 <recently read> }
 l. ...  }
 ! Undefined control sequence.
@@ -67,7 +67,7 @@
 misspelled it (e.g., `\hobx'), type `I' and the correct
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
-> \l_tmpa_tl=1e10000.
+> \l_tmpa_tl=1.000000000000000e10000.
 <recently read> }
 l. ...  }
 ! Undefined control sequence.
@@ -79,7 +79,7 @@
 misspelled it (e.g., `\hobx'), type `I' and the correct
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
-> \l_tmpa_tl=1e10000.
+> \l_tmpa_tl=1.000000000000000e10000.
 <recently read> }
 l. ...  }
 ! Undefined control sequence.
@@ -91,7 +91,7 @@
 misspelled it (e.g., `\hobx'), type `I' and the correct
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
-> \l_tmpa_tl=0.
+> \l_tmpa_tl=0.000000000000000e0.
 <recently read> }
 l. ...  }
 ! Undefined control sequence.
@@ -103,7 +103,7 @@
 misspelled it (e.g., `\hobx'), type `I' and the correct
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
-> \l_tmpa_tl=0.
+> \l_tmpa_tl=0.000000000000000e0.
 <recently read> }
 l. ...  }
 ============================================================



More information about the latex3-commits mailing list