[latex3-commits] [git/LaTeX3-latex3-latex3] master: Correct fp randint with zero argument (fixes #507) (6a07f90)

Bruno Le Floch bruno at le-floch.fr
Thu Dec 20 17:23:52 CET 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/6a07f90e1f478d6b1e307fe38eb9241320c3128f

>---------------------------------------------------------------

commit 6a07f90e1f478d6b1e307fe38eb9241320c3128f
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Thu Dec 20 17:23:52 2018 +0100

    Correct fp randint with zero argument (fixes #507)
    
    I had thought integers are always normal fp numbers, but they can of course be
    zero too


>---------------------------------------------------------------

6a07f90e1f478d6b1e307fe38eb9241320c3128f
 l3kernel/l3fp-random.dtx               |   28 ++++++++++++++++++----------
 l3kernel/testfiles/m3rand001.lvt       |    6 ++++++
 l3kernel/testfiles/m3rand001.tlg       |    9 +++++++++
 l3kernel/testfiles/m3rand001.xetex.tlg |   14 ++++++++++++++
 4 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/l3kernel/l3fp-random.dtx b/l3kernel/l3fp-random.dtx
index 038f222..97bd00e 100644
--- a/l3kernel/l3fp-random.dtx
+++ b/l3kernel/l3fp-random.dtx
@@ -421,19 +421,27 @@
         \@@_randint_auxii:wn #2 ;
         { \@@_randint_auxii:wn #1 ; \@@_randint_auxiii_o:ww }
       }
-    \cs_new:Npn \@@_randint_auxii:wn \s_@@ \@@_chk:w 1#1#2#3 ;
+    \cs_new:Npn \@@_randint_auxii:wn \s_@@ \@@_chk:w #1#2#3#4 ;
       {
-        \exp_after:wN \@@_ep_to_fixed:wwn
-        \int_value:w \@@_int_eval:w
-          #2 - \c_@@_prec_int , #3 {0000} {0000} ;
+        \if_meaning:w 0 #1
+          \exp_after:wN \use_i:nn
+        \else:
+          \exp_after:wN \use_ii:nn
+        \fi:
+        { \exp_after:wN \@@_fixed_continue:wn \c_@@_one_fixed_tl }
         {
-          \if_meaning:w 0 #1
-            \exp_after:wN \use_i:nnnn
-            \exp_after:wN \@@_fixed_add_one:wN
-          \fi:
-          \exp_after:wN \@@_fixed_sub:wwn \c_@@_one_fixed_tl
+          \exp_after:wN \@@_ep_to_fixed:wwn
+          \int_value:w \@@_int_eval:w
+            #3 - \c_@@_prec_int , #4 {0000} {0000} ;
+          {
+            \if_meaning:w 0 #2
+              \exp_after:wN \use_i:nnnn
+              \exp_after:wN \@@_fixed_add_one:wN
+            \fi:
+            \exp_after:wN \@@_fixed_sub:wwn \c_@@_one_fixed_tl
+          }
+          \@@_fixed_continue:wn
         }
-        \@@_fixed_continue:wn
       }
     \cs_new:Npn \@@_randint_auxiii_o:ww #1 ; #2 ;
       {
diff --git a/l3kernel/testfiles/m3rand001.lvt b/l3kernel/testfiles/m3rand001.lvt
index e614c3c..90c7ecd 100644
--- a/l3kernel/testfiles/m3rand001.lvt
+++ b/l3kernel/testfiles/m3rand001.lvt
@@ -185,4 +185,10 @@
   }
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\TESTEXP { Random~integer~(issue~507) }
+  {
+    \test:n { randint(0,2) }
+  }
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \END
diff --git a/l3kernel/testfiles/m3rand001.tlg b/l3kernel/testfiles/m3rand001.tlg
index d9d25f8..b62f6c1 100644
--- a/l3kernel/testfiles/m3rand001.tlg
+++ b/l3kernel/testfiles/m3rand001.tlg
@@ -323,3 +323,12 @@ TEST 12: Random intarray contents
 -1,0,2,-2,2,-1,2,-2,3,-1,3,2,0,4,5
 820580739,-112220571,-698712122,-22653540,596754623,569851830,-76814189,812455767,554030471,858568271,-761913564,-698174727,-492774578,-1035763579,1060453552
 ============================================================
+============================================================
+TEST 13: Random integer (issue 507)
+============================================================
+0
+2
+0
+1
+2
+============================================================
diff --git a/l3kernel/testfiles/m3rand001.xetex.tlg b/l3kernel/testfiles/m3rand001.xetex.tlg
index 7ac4507..13f02d7 100644
--- a/l3kernel/testfiles/m3rand001.xetex.tlg
+++ b/l3kernel/testfiles/m3rand001.xetex.tlg
@@ -539,3 +539,17 @@ Try typing <return> to proceed.
 If that doesn't work, type X <return> to quit.
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 ============================================================
+============================================================
+TEST 13: Random integer (issue 507)
+============================================================
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Random numbers unavailable for fp rand
+l. ...  }
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+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.
+nan, 
+============================================================





More information about the latex3-commits mailing list