[latex3-commits] [git/LaTeX3-latex3-latex3] master: Make a "randint" function/variable into kernel functions (3b79a33)

Bruno Le Floch bruno at le-floch.fr
Sun May 6 16:13:51 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/3b79a3330a434b529947e347f0ba4332d3b28a7f

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

commit 3b79a3330a434b529947e347f0ba4332d3b28a7f
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sat May 5 20:16:19 2018 -0400

    Make a "randint" function/variable into kernel functions


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

3b79a3330a434b529947e347f0ba4332d3b28a7f
 l3kernel/l3fp-random.dtx                |   24 ++++++++++++------------
 l3kernel/l3kernel-functions.dtx         |   14 ++++++++++++++
 l3kernel/testfiles/m3expl001.luatex.tlg |    4 ++--
 l3kernel/testfiles/m3expl001.ptex.tlg   |    6 +++---
 l3kernel/testfiles/m3expl001.tlg        |    6 +++---
 l3kernel/testfiles/m3expl001.uptex.tlg  |    4 ++--
 l3kernel/testfiles/m3expl002.ptex.tlg   |    2 +-
 l3kernel/testfiles/m3expl002.tlg        |    2 +-
 l3kernel/testfiles/m3expl003.luatex.tlg |    4 ++--
 l3kernel/testfiles/m3expl003.ptex.tlg   |    6 +++---
 l3kernel/testfiles/m3expl003.tlg        |    6 +++---
 l3kernel/testfiles/m3expl003.uptex.tlg  |    4 ++--
 l3kernel/testfiles/m3expl004.ptex.tlg   |    2 +-
 l3kernel/testfiles/m3expl004.tlg        |    2 +-
 l3kernel/testfiles/m3expl006.ptex.tlg   |    2 +-
 l3kernel/testfiles/m3expl006.tlg        |    2 +-
 16 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/l3kernel/l3fp-random.dtx b/l3kernel/l3fp-random.dtx
index ecd74de..5c19766 100644
--- a/l3kernel/l3fp-random.dtx
+++ b/l3kernel/l3fp-random.dtx
@@ -232,22 +232,22 @@
 %   \pkg{l3fp-extended} only supports non-negative numbers.
 % \end{itemize}
 %
-% \begin{variable}{\c_@@_rand_critical_int}
+% \begin{variable}{\c__kernel_randint_max_int}
 %   Constant equal to $2^{17}$, the maximal size of a range that
 %   \cs{int_range:nn} can do with its \enquote{simple} algorithm.
 %    \begin{macrocode}
-    \int_const:Nn \c_@@_rand_critical_int {   13 1072 }
+    \int_const:Nn \c__kernel_randint_max_int { 131072 }
 %    \end{macrocode}
 % \end{variable}
 %
-% \begin{macro}[EXP]{\@@_randint:nn}
-%   Used in an integer expression, \cs{@@_randint:nn} \Arg{min}
+% \begin{macro}[EXP]{\__kernel_randint:nn}
+%   Used in an integer expression, \cs{__kernel_randint:nn} \Arg{min}
 %   |{|$R$|}| gives a random number
 %   $\lfloor(R\operatorname{random}(2^{14}) +
 %   \operatorname{random}(R))/2^{14}\rfloor$.  that is between
 %   \meta{min} and $\meta{min}+R-1$ inclusive.
 %    \begin{macrocode}
-    \cs_new:Npn \@@_randint:nn #1#2
+    \cs_new:Npn \__kernel_randint:nn #1#2
       {
         #1 + (#2 * \tex_uniformdeviate:D 1 6384
               + \tex_uniformdeviate:D #2 - 8192 ) / 16384
@@ -270,7 +270,7 @@
         #1
         \exp_after:wN \@@_rand_myriads_get:w
         \int_value:w \@@_int_eval:w
-          \@@_randint:nn { 10000 } { 10000 }
+          \__kernel_randint:nn { 10000 } { 10000 }
         \@@_rand_myriads_loop:w
       }
     \cs_new:Npn \@@_rand_myriads_get:w 1 #1 ; { ; {#1} }
@@ -452,10 +452,10 @@
 % \begin{macro}{\int_rand:nn, \@@_randint:ww}
 %   Evaluate the argument and filter out the case where the lower
 %   bound~|#1| is more than the upper bound~|#2|.  Then determine
-%   whether the range is narrower than \cs{c_@@_rand_critical_int};
+%   whether the range is narrower than \cs{c__kernel_randint_max_int};
 %   |#2-#1| may overflow for very large positive~|#2| and negative~|#1|.
 %   If the range is wide, use slower code from \pkg{l3fp}.  If the range
-%   is narrow, call \cs{@@_randint:nn} |{#1}| \Arg{choices} where
+%   is narrow, call \cs{__kernel_randint:nn} |{#1}| \Arg{choices} where
 %   \meta{choices} is the number of possible outcomes.
 %    \begin{macrocode}
     \cs_new:Npn \int_rand:nn #1#2
@@ -480,9 +480,9 @@
               \else:
                 < \@@_int_eval:w #1 +
               \fi:
-              \c_@@_rand_critical_int
+              \c__kernel_randint_max_int
               \@@_int_eval_end:
-            \@@_randint:nn {#1}
+            \__kernel_randint:nn {#1}
               { \@@_int_eval:w #2 - #1 + 1 \@@_int_eval_end: }
           \else:
             \fp_to_int:n { randint(#1,#2) }
@@ -507,10 +507,10 @@
             { kernel } { randint-backward-range } { 1 } {#1}
           \@@_randint:ww #1; 1;
         \else:
-          \if_int_compare:w #1 > \c_@@_rand_critical_int
+          \if_int_compare:w #1 > \c__kernel_randint_max_int
             \fp_to_int:n { randint(#1) }
           \else:
-            \@@_randint:nn {1} {#1}
+            \__kernel_randint:nn {1} {#1}
           \fi:
         \fi:
       }
diff --git a/l3kernel/l3kernel-functions.dtx b/l3kernel/l3kernel-functions.dtx
index 67a2d60..0883990 100644
--- a/l3kernel/l3kernel-functions.dtx
+++ b/l3kernel/l3kernel-functions.dtx
@@ -429,6 +429,20 @@
 %   and variable mappings.
 % \end{variable}
 %
+% \begin{function}{\__kernel_randint:nn}
+%   \begin{syntax}
+%     \cs{__kernel_randint:nn} \Arg{min} \Arg{choices}
+%   \end{syntax}
+%   Used in an integer expression this gives a pseudo-random number
+%   between \meta{min} and $\meta{min} + \meta{choices} - 1$ included.
+%   One must have $\meta{choices}\leq 2^{17}$.
+% \end{function}
+%
+% \begin{variable}{\c__kernel_randint_max_int}
+%   Maximal allowed second argument to \cs{__kernel_randint:nn}.  Equal
+%   to $2^{17}$.
+% \end{variable}
+%
 % \begin{function}{\__kernel_register_show:N, \__kernel_register_show:c}
 %   \begin{syntax}
 %     \cs{__kernel_register_show:N} \meta{register}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index f6b12e7..6ff4b8b 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -4225,8 +4225,8 @@ Defining \__fp_array_to_clist:n on line ...
 Defining \__fp_array_to_clist_loop:Nw on line ...
 Defining \__fp_parse_word_rand:N on line ...
 Defining \__fp_parse_word_randint:N on line ...
-Defining \c__fp_rand_critical_int on line ...
-Defining \__fp_randint:nn on line ...
+Defining \c__kernel_randint_max_int on line ...
+Defining \__kernel_randint:nn on line ...
 Defining \__fp_rand_myriads:n on line ...
 Defining \__fp_rand_myriads_loop:w on line ...
 Defining \__fp_rand_myriads_get:w on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index d587461..5fe6b6e 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -4479,9 +4479,9 @@ Defining \__fp_array_to_clist:n on line ...
 Defining \__fp_array_to_clist_loop:Nw on line ...
 Defining \__fp_parse_word_rand:N on line ...
 Defining \__fp_parse_word_randint:N on line ...
-Defining \c__fp_rand_critical_int on line ...
-\c__fp_rand_critical_int=\count...
-Defining \__fp_randint:nn on line ...
+Defining \c__kernel_randint_max_int on line ...
+\c__kernel_randint_max_int=\count...
+Defining \__kernel_randint:nn on line ...
 Defining \__fp_rand_myriads:n on line ...
 Defining \__fp_rand_myriads_loop:w on line ...
 Defining \__fp_rand_myriads_get:w on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index eb00310..c067bdb 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -4479,9 +4479,9 @@ Defining \__fp_array_to_clist:n on line ...
 Defining \__fp_array_to_clist_loop:Nw on line ...
 Defining \__fp_parse_word_rand:N on line ...
 Defining \__fp_parse_word_randint:N on line ...
-Defining \c__fp_rand_critical_int on line ...
-\c__fp_rand_critical_int=\count...
-Defining \__fp_randint:nn on line ...
+Defining \c__kernel_randint_max_int on line ...
+\c__kernel_randint_max_int=\count...
+Defining \__kernel_randint:nn on line ...
 Defining \__fp_rand_myriads:n on line ...
 Defining \__fp_rand_myriads_loop:w on line ...
 Defining \__fp_rand_myriads_get:w on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 1194d42..18954cf 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -4479,8 +4479,8 @@ Defining \__fp_array_to_clist:n on line ...
 Defining \__fp_array_to_clist_loop:Nw on line ...
 Defining \__fp_parse_word_rand:N on line ...
 Defining \__fp_parse_word_randint:N on line ...
-Defining \c__fp_rand_critical_int on line ...
-Defining \__fp_randint:nn on line ...
+Defining \c__kernel_randint_max_int on line ...
+Defining \__kernel_randint:nn on line ...
 Defining \__fp_rand_myriads:n on line ...
 Defining \__fp_rand_myriads_loop:w on line ...
 Defining \__fp_rand_myriads_get:w on line ...
diff --git a/l3kernel/testfiles/m3expl002.ptex.tlg b/l3kernel/testfiles/m3expl002.ptex.tlg
index 92bd5e4..99dd3f7 100644
--- a/l3kernel/testfiles/m3expl002.ptex.tlg
+++ b/l3kernel/testfiles/m3expl002.ptex.tlg
@@ -44,7 +44,7 @@ Don't change this file in any respect.
 \c__fp_Bigg_leading_shift_int=\count...
 \c__fp_Bigg_middle_shift_int=\count...
 \c__fp_Bigg_trailing_shift_int=\count...
-\c__fp_rand_critical_int=\count...
+\c__kernel_randint_max_int=\count...
 \g__fp_array_int=\count...
 \l__fp_array_loop_int=\count...
 \l__sort_length_int=\count...
diff --git a/l3kernel/testfiles/m3expl002.tlg b/l3kernel/testfiles/m3expl002.tlg
index b231a97..b0cb6f2 100644
--- a/l3kernel/testfiles/m3expl002.tlg
+++ b/l3kernel/testfiles/m3expl002.tlg
@@ -44,7 +44,7 @@ Don't change this file in any respect.
 \c__fp_Bigg_leading_shift_int=\count...
 \c__fp_Bigg_middle_shift_int=\count...
 \c__fp_Bigg_trailing_shift_int=\count...
-\c__fp_rand_critical_int=\count...
+\c__kernel_randint_max_int=\count...
 \g__fp_array_int=\count...
 \l__fp_array_loop_int=\count...
 \l__sort_length_int=\count...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index f6b12e7..6ff4b8b 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -4225,8 +4225,8 @@ Defining \__fp_array_to_clist:n on line ...
 Defining \__fp_array_to_clist_loop:Nw on line ...
 Defining \__fp_parse_word_rand:N on line ...
 Defining \__fp_parse_word_randint:N on line ...
-Defining \c__fp_rand_critical_int on line ...
-Defining \__fp_randint:nn on line ...
+Defining \c__kernel_randint_max_int on line ...
+Defining \__kernel_randint:nn on line ...
 Defining \__fp_rand_myriads:n on line ...
 Defining \__fp_rand_myriads_loop:w on line ...
 Defining \__fp_rand_myriads_get:w on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index d587461..5fe6b6e 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -4479,9 +4479,9 @@ Defining \__fp_array_to_clist:n on line ...
 Defining \__fp_array_to_clist_loop:Nw on line ...
 Defining \__fp_parse_word_rand:N on line ...
 Defining \__fp_parse_word_randint:N on line ...
-Defining \c__fp_rand_critical_int on line ...
-\c__fp_rand_critical_int=\count...
-Defining \__fp_randint:nn on line ...
+Defining \c__kernel_randint_max_int on line ...
+\c__kernel_randint_max_int=\count...
+Defining \__kernel_randint:nn on line ...
 Defining \__fp_rand_myriads:n on line ...
 Defining \__fp_rand_myriads_loop:w on line ...
 Defining \__fp_rand_myriads_get:w on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index eb00310..c067bdb 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -4479,9 +4479,9 @@ Defining \__fp_array_to_clist:n on line ...
 Defining \__fp_array_to_clist_loop:Nw on line ...
 Defining \__fp_parse_word_rand:N on line ...
 Defining \__fp_parse_word_randint:N on line ...
-Defining \c__fp_rand_critical_int on line ...
-\c__fp_rand_critical_int=\count...
-Defining \__fp_randint:nn on line ...
+Defining \c__kernel_randint_max_int on line ...
+\c__kernel_randint_max_int=\count...
+Defining \__kernel_randint:nn on line ...
 Defining \__fp_rand_myriads:n on line ...
 Defining \__fp_rand_myriads_loop:w on line ...
 Defining \__fp_rand_myriads_get:w on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 1194d42..18954cf 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -4479,8 +4479,8 @@ Defining \__fp_array_to_clist:n on line ...
 Defining \__fp_array_to_clist_loop:Nw on line ...
 Defining \__fp_parse_word_rand:N on line ...
 Defining \__fp_parse_word_randint:N on line ...
-Defining \c__fp_rand_critical_int on line ...
-Defining \__fp_randint:nn on line ...
+Defining \c__kernel_randint_max_int on line ...
+Defining \__kernel_randint:nn on line ...
 Defining \__fp_rand_myriads:n on line ...
 Defining \__fp_rand_myriads_loop:w on line ...
 Defining \__fp_rand_myriads_get:w on line ...
diff --git a/l3kernel/testfiles/m3expl004.ptex.tlg b/l3kernel/testfiles/m3expl004.ptex.tlg
index 92bd5e4..99dd3f7 100644
--- a/l3kernel/testfiles/m3expl004.ptex.tlg
+++ b/l3kernel/testfiles/m3expl004.ptex.tlg
@@ -44,7 +44,7 @@ Don't change this file in any respect.
 \c__fp_Bigg_leading_shift_int=\count...
 \c__fp_Bigg_middle_shift_int=\count...
 \c__fp_Bigg_trailing_shift_int=\count...
-\c__fp_rand_critical_int=\count...
+\c__kernel_randint_max_int=\count...
 \g__fp_array_int=\count...
 \l__fp_array_loop_int=\count...
 \l__sort_length_int=\count...
diff --git a/l3kernel/testfiles/m3expl004.tlg b/l3kernel/testfiles/m3expl004.tlg
index b231a97..b0cb6f2 100644
--- a/l3kernel/testfiles/m3expl004.tlg
+++ b/l3kernel/testfiles/m3expl004.tlg
@@ -44,7 +44,7 @@ Don't change this file in any respect.
 \c__fp_Bigg_leading_shift_int=\count...
 \c__fp_Bigg_middle_shift_int=\count...
 \c__fp_Bigg_trailing_shift_int=\count...
-\c__fp_rand_critical_int=\count...
+\c__kernel_randint_max_int=\count...
 \g__fp_array_int=\count...
 \l__fp_array_loop_int=\count...
 \l__sort_length_int=\count...
diff --git a/l3kernel/testfiles/m3expl006.ptex.tlg b/l3kernel/testfiles/m3expl006.ptex.tlg
index fab5064..e05792b 100644
--- a/l3kernel/testfiles/m3expl006.ptex.tlg
+++ b/l3kernel/testfiles/m3expl006.ptex.tlg
@@ -45,7 +45,7 @@ Author: Bruno Le Floch and Joseph Wright
 \c__fp_Bigg_leading_shift_int=\count...
 \c__fp_Bigg_middle_shift_int=\count...
 \c__fp_Bigg_trailing_shift_int=\count...
-\c__fp_rand_critical_int=\count...
+\c__kernel_randint_max_int=\count...
 \g__fp_array_int=\count...
 \l__fp_array_loop_int=\count...
 \l__sort_length_int=\count...
diff --git a/l3kernel/testfiles/m3expl006.tlg b/l3kernel/testfiles/m3expl006.tlg
index d238cf6..f71f2cd 100644
--- a/l3kernel/testfiles/m3expl006.tlg
+++ b/l3kernel/testfiles/m3expl006.tlg
@@ -45,7 +45,7 @@ Author: Bruno Le Floch and Joseph Wright
 \c__fp_Bigg_leading_shift_int=\count...
 \c__fp_Bigg_middle_shift_int=\count...
 \c__fp_Bigg_trailing_shift_int=\count...
-\c__fp_rand_critical_int=\count...
+\c__kernel_randint_max_int=\count...
 \g__fp_array_int=\count...
 \l__fp_array_loop_int=\count...
 \l__sort_length_int=\count...





More information about the latex3-commits mailing list