[latex3-commits] [git/LaTeX3-latex3-latex3] luaintarray: Move Random arrays to common block (5002cb13a)

Marcel Fabian Krüger tex at 2krueger.de
Sat Nov 13 09:53:15 CET 2021


Repository : https://github.com/latex3/latex3
On branch  : luaintarray
Link       : https://github.com/latex3/latex3/commit/5002cb13aa59f23349c85027a6f4d817676d48f6

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

commit 5002cb13aa59f23349c85027a6f4d817676d48f6
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Sat Nov 13 09:32:00 2021 +0100

    Move Random arrays to common block


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

5002cb13aa59f23349c85027a6f4d817676d48f6
 l3kernel/l3intarray.dtx | 106 ++++++++----------------------------------------
 1 file changed, 16 insertions(+), 90 deletions(-)

diff --git a/l3kernel/l3intarray.dtx b/l3kernel/l3intarray.dtx
index e86564154..a81cf2fba 100644
--- a/l3kernel/l3intarray.dtx
+++ b/l3kernel/l3intarray.dtx
@@ -594,105 +594,24 @@ luacmd('@@_gset_range:wNw', function()
 %    \end{macrocode}
 % \end{macro}
 %
-% \subsubsection{Random arrays}
-%
-% \begin{macro}{\intarray_gset_rand:Nn, \intarray_gset_rand:cn}
-% \begin{macro}{\intarray_gset_rand:Nnn, \intarray_gset_rand:cnn}
-% \begin{macro}
-%   {
-%     \@@_gset_rand:Nnn,
-%     \@@_gset_rand:Nff,
-%     \@@_gset_rand_auxi:Nnnn,
-%     \@@_gset_rand_auxii:Nnnn,
-%     \@@_gset_rand_auxiii:Nnnn,
-%     \@@_gset_all_same:Nn,
-%   }
-%   We only perform the bounds checks once.  This is done by two
-%   \cs{@@_gset_overflow_test:nw}, with an appropriate empty argument to
-%   avoid a spurious \enquote{at position \texttt{\#1}} part in the
-%   error message.  Then calculate the number of choices: this is at
-%   most $(2^{30}-1)-(-(2^{30}-1))+1=2^{31}-1$, which just barely does
-%   not overflow.  For small ranges use \cs{__kernel_randint:n} (making
-%   sure to subtract~$1$ \emph{before} adding the random number to the
-%   \meta{min}, to avoid overflow when \meta{min} or \meta{max} are
-%   $\pm\cs{c_max_int}$), otherwise \cs{__kernel_randint:nn}.  Finally,
-%   if there are no random numbers do not define any of the auxiliaries.
+% \begin{macro}{\@@_gset_overflow_test:nw}
+%   In order to allow some code sharing later we provide the
+%   \cs{@@_gset_overflow_test:nw} name here. It doesn't actually test anything
+%   since the Lua implementation accepts all integers which could be tested with
+%   \cs{tex_ifabsnum:D}.
 %    \begin{macrocode}
-\cs_new_protected:Npn \intarray_gset_rand:Nn #1
-  { \intarray_gset_rand:Nnn #1 { 1 } }
-\cs_generate_variant:Nn \intarray_gset_rand:Nn { c }
-\sys_if_rand_exist:TF
-  {
-    \cs_new_protected:Npn \intarray_gset_rand:Nnn #1#2#3
-      {
-        \@@_gset_rand:Nff #1
-          { \int_eval:n {#2} } { \int_eval:n {#3} }
-      }
-    \cs_new_protected:Npn \@@_gset_rand:Nnn #1#2#3
-      {
-        \int_compare:nNnTF {#2} > {#3}
-          {
-            \msg_expandable_error:nnnn
-              { kernel } { randint-backward-range } {#2} {#3}
-            \@@_gset_rand:Nnn #1 {#3} {#2}
-          }
-          {
-            \@@_gset_rand_auxi:Nnnn #1 { } {#2} {#3}
-          }
-      }
-    \cs_generate_variant:Nn \@@_gset_rand:Nnn { Nff }
-    \cs_new_protected:Npn \@@_gset_rand_auxi:Nnnn #1#2#3#4
-      {
-        \@@_gset_rand_auxii:Nnnn #1 { } {#4} {#3}
-      }
-    \cs_new_protected:Npn \@@_gset_rand_auxii:Nnnn #1#2#3#4
-      {
-        \exp_args:NNf \@@_gset_rand_auxiii:Nnnn #1
-          { \int_eval:n { #3 - #4 + 1 } } {#4} {#3}
-      }
-    \cs_new_protected:Npn \@@_gset_rand_auxiii:Nnnn #1#2#3#4
-      {
-        \exp_args:NNf \@@_gset_all_same:Nn #1
-          {
-            \int_compare:nNnTF {#2} > \c__kernel_randint_max_int
-              {
-                \exp_stop_f:
-                \int_eval:n { \__kernel_randint:nn {#3} {#4} }
-              }
-              {
-                \exp_stop_f:
-                \int_eval:n { \__kernel_randint:n {#2} - 1 + #3 }
-              }
-          }
-      }
-    \cs_new_protected:Npn \@@_gset_all_same:Nn #1#2
-      {
-        \int_zero:N \l_@@_loop_int
-        \prg_replicate:nn { \intarray_count:N #1 }
-          {
-            \int_incr:N \l_@@_loop_int
-            \__kernel_intarray_gset:Nnn #1 \l_@@_loop_int {#2}
-          }
-      }
-  }
+\cs_new_protected:Npn \@@_gset_overflow_test:nw #1
   {
-    \cs_new_protected:Npn \intarray_gset_rand:Nnn #1#2#3
-      {
-        \msg_error:nnn { kernel } { fp-no-random }
-          { \intarray_gset_rand:Nnn #1 {#2} {#3} }
-      }
   }
-\cs_generate_variant:Nn \intarray_gset_rand:Nnn { c }
 %    \end{macrocode}
 % \end{macro}
-% \end{macro}
-% \end{macro}
 %
 % \subsection{Font dimension based implementation}
 %
 % Go to the false branch of the conditional above.
 %    \begin{macrocode}
-}{
+}
+{
 %    \end{macrocode}
 %
 % \subsubsection{Allocating arrays}
@@ -1049,6 +968,14 @@ luacmd('@@_gset_range:wNw', function()
 %    \end{macrocode}
 % \end{macro}
 %
+%    \begin{macrocode}
+}
+%    \end{macrocode}
+%
+% \subsection{Common parts}
+% Finally some code is shared between both implementations.
+% Currently this is only the support for random arrays.
+%
 % \subsubsection{Random arrays}
 %
 % \begin{macro}{\intarray_gset_rand:Nn, \intarray_gset_rand:cn}
@@ -1146,7 +1073,6 @@ luacmd('@@_gset_range:wNw', function()
 % \end{macro}
 %
 %    \begin{macrocode}
-}
 %</tex>
 %</package>
 %    \end{macrocode}





More information about the latex3-commits mailing list.