[latex3-commits] [latex3/latex3] int-if-zero: Add \int_if_zero:n(TF) (closes #1205) (859a756f8)

github at latex-project.org github at latex-project.org
Wed May 17 07:53:39 CEST 2023


Repository : https://github.com/latex3/latex3
On branch  : int-if-zero
Link       : https://github.com/latex3/latex3/commit/859a756f899f9e88109308e8d63eca89722ba1f6

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

commit 859a756f899f9e88109308e8d63eca89722ba1f6
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Wed May 17 06:53:21 2023 +0100

    Add \int_if_zero:n(TF) (closes #1205)


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

859a756f899f9e88109308e8d63eca89722ba1f6
 l3kernel/l3int.dtx              |  24 ++++++++++
 l3kernel/testfiles/m3int002.lvt |  15 ++++++
 l3kernel/testfiles/m3int002.tlg | 102 ++++++++++++++++++++++------------------
 3 files changed, 96 insertions(+), 45 deletions(-)

diff --git a/l3kernel/l3int.dtx b/l3kernel/l3int.dtx
index f7d065d87..a0c3d2113 100644
--- a/l3kernel/l3int.dtx
+++ b/l3kernel/l3int.dtx
@@ -493,6 +493,17 @@
 %   is odd or even, as appropriate.
 % \end{function}
 %
+% \begin{function}[EXP,pTF, added = 2023-05-17]{\int_if_zero:n, \int_if_zero:n}
+%   \begin{syntax}
+%     \cs{int_if_zero_p:n} \Arg{int expr}
+%     \cs{int_if_zero:nTF} \Arg{int expr}
+%     ~~\Arg{true code} \Arg{false code}
+%   \end{syntax}
+%   This function first evaluates the \meta{int expr}
+%   as described for \cs{int_eval:n}. It then evaluates if this
+%   is zero or not.
+% \end{function}
+%
 % \section{Integer expression loops}
 %
 % \begin{function}[rEXP]{\int_do_until:nNnn}
@@ -1730,6 +1741,19 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}[pTF]{\int_if_zero:n}
+%    \begin{macrocode}
+\prg_new_conditional:Npnn \int_if_zero:n #1 { p , T , F , TF }
+  {
+    \if_int_compare:w \@@_eval:w #1 = 0 \exp_stop_f:
+      \prg_return_true:
+    \else:
+      \prg_return_false:
+    \fi:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}[EXP, noTF]{\int_case:nn}
 % \begin{macro}{\@@_case:nnTF}
 % \begin{macro}{\@@_case:nw, \@@_case_end:nw}
diff --git a/l3kernel/testfiles/m3int002.lvt b/l3kernel/testfiles/m3int002.lvt
index 2f0277503..7536400bb 100644
--- a/l3kernel/testfiles/m3int002.lvt
+++ b/l3kernel/testfiles/m3int002.lvt
@@ -124,6 +124,21 @@
   \int_if_odd:nF { -1 }    { \ERROR } \NEWLINE
 }
 
+\TESTEXP { Integer~tests:~if~zero } {
+  \int_if_zero:nTF { 1 + 4 } { \ERROR } { \FALSE } \NEWLINE
+  \int_if_zero:nTF { 1 + 3 } { \ERROR } { \FALSE } \NEWLINE
+  \int_if_zero:nTF { 0 }     { \TRUE } { \ERROR } \NEWLINE
+  \int_if_zero:nTF { -1 }    { \ERROR } { \FALSE } \NEWLINE
+  \int_if_zero:nT { 1 + 4 } { \ERROR } \NEWLINE
+  \int_if_zero:nT { 1 + 3 } { \ERROR } \NEWLINE
+  \int_if_zero:nT { 0 }     { \TRUE } \NEWLINE
+  \int_if_zero:nT { -1 }    { \ERROR } \NEWLINE
+  \int_if_zero:nF { 1 + 4 } { \FALSE } \NEWLINE
+  \int_if_zero:nF { 1 + 3 } { \FALSE } \NEWLINE
+  \int_if_zero:nF { 0 }     { \ERROR } \NEWLINE
+  \int_if_zero:nF { -1 }    { \FALSE } \NEWLINE
+}
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 \TEST { Integer~while-do~and~do-while } {
diff --git a/l3kernel/testfiles/m3int002.tlg b/l3kernel/testfiles/m3int002.tlg
index 08a28cefc..3c47fa22c 100644
--- a/l3kernel/testfiles/m3int002.tlg
+++ b/l3kernel/testfiles/m3int002.tlg
@@ -62,7 +62,19 @@ FALSE
 FALSE
 ============================================================
 ============================================================
-TEST 7: Integer while-do and do-while
+TEST 7: Integer tests: if zero
+============================================================
+FALSE
+FALSE
+TRUE
+FALSE
+TRUE
+FALSE
+FALSE
+FALSE
+============================================================
+============================================================
+TEST 8: Integer while-do and do-while
 ============================================================
 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
 ============================================================
@@ -72,7 +84,7 @@ TEST 7: Integer while-do and do-while
 [10]
 ============================================================
 ============================================================
-TEST 8: Integer until-do and do-until
+TEST 9: Integer until-do and do-until
 ============================================================
 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
 ============================================================
@@ -83,14 +95,14 @@ TEST 8: Integer until-do and do-until
 [10]
 ============================================================
 ============================================================
-TEST 9: Evaluating integer expressions
+TEST 10: Evaluating integer expressions
 ============================================================
 10
 10
 22
 ============================================================
 ============================================================
-TEST 10: Absolute value for integers
+TEST 11: Absolute value for integers
 ============================================================
 0
 10
@@ -100,7 +112,7 @@ TEST 10: Absolute value for integers
 45
 ============================================================
 ============================================================
-TEST 11: Integer division: truncation
+TEST 12: Integer division: truncation
 ============================================================
 2
 2
@@ -127,7 +139,7 @@ TEST 11: Integer division: truncation
 2
 ============================================================
 ============================================================
-TEST 12: Maximum and minimum integers
+TEST 13: Maximum and minimum integers
 ============================================================
 11
 7
@@ -145,7 +157,7 @@ TEST 12: Maximum and minimum integers
 -999
 ============================================================
 ============================================================
-TEST 13: Integer division: modulo
+TEST 14: Integer division: modulo
 ============================================================
 0
 4
@@ -161,7 +173,7 @@ TEST 13: Integer division: modulo
 -4
 ============================================================
 ============================================================
-TEST 14: Integer creation
+TEST 15: Integer creation
 ============================================================
 Defining \l_A_int on line ...
 \l_A_int=\count...
@@ -179,7 +191,7 @@ Defining \g_B_int on line ...
 \count305
 ============================================================
 ============================================================
-TEST 15: Integer creation errors
+TEST 16: Integer creation errors
 ============================================================
 ! LaTeX Error: Control sequence \l_A_int already defined.
 For immediate help type H <return>.
@@ -227,7 +239,7 @@ Defining \g_B_int on line ...
 \g_B_int=\count...
 ============================================================
 ============================================================
-TEST 16: Constant integer creation
+TEST 17: Constant integer creation
 ============================================================
 Defining \c_A_int on line ...
 \mathchar"5
@@ -240,7 +252,7 @@ Defining \c_B_int on line ...
 -10
 ============================================================
 ============================================================
-TEST 17: Constant integer creation errors
+TEST 18: Constant integer creation errors
 ============================================================
 ! LaTeX Error: Control sequence \c_A_int already defined.
 For immediate help type H <return>.
@@ -265,7 +277,7 @@ Defining \c_B_int on line ...
 \c_B_int=\count...
 ============================================================
 ============================================================
-TEST 18: Set integers equal
+TEST 19: Set integers equal
 ============================================================
 4
 0
@@ -277,7 +289,7 @@ TEST 18: Set integers equal
 0
 ============================================================
 ============================================================
-TEST 19: Set integers equal globally
+TEST 20: Set integers equal globally
 ============================================================
 4
 4
@@ -289,7 +301,7 @@ TEST 19: Set integers equal globally
 4
 ============================================================
 ============================================================
-TEST 20: Add to integers
+TEST 21: Add to integers
 ============================================================
 8
 -2
@@ -299,7 +311,7 @@ TEST 20: Add to integers
 0
 ============================================================
 ============================================================
-TEST 21: Add to integers globally
+TEST 22: Add to integers globally
 ============================================================
 8
 -2
@@ -309,7 +321,7 @@ TEST 21: Add to integers globally
 -4
 ============================================================
 ============================================================
-TEST 22: Decreasing integers
+TEST 23: Decreasing integers
 ============================================================
 -1
 -2
@@ -319,7 +331,7 @@ TEST 22: Decreasing integers
 0
 ============================================================
 ============================================================
-TEST 23: Decreasing integers globally
+TEST 24: Decreasing integers globally
 ============================================================
 -1
 -2
@@ -329,7 +341,7 @@ TEST 23: Decreasing integers globally
 -4
 ============================================================
 ============================================================
-TEST 24: Increasing integers
+TEST 25: Increasing integers
 ============================================================
 1
 2
@@ -339,7 +351,7 @@ TEST 24: Increasing integers
 0
 ============================================================
 ============================================================
-TEST 25: Increasing integers globally
+TEST 26: Increasing integers globally
 ============================================================
 1
 2
@@ -349,7 +361,7 @@ TEST 25: Increasing integers globally
 4
 ============================================================
 ============================================================
-TEST 26: Setting integers to arbitrary values
+TEST 27: Setting integers to arbitrary values
 ============================================================
 0
 2147483647
@@ -363,7 +375,7 @@ TEST 26: Setting integers to arbitrary values
 0
 ============================================================
 ============================================================
-TEST 27: Setting integers to arbitrary values globally
+TEST 28: Setting integers to arbitrary values globally
 ============================================================
 0
 2147483647
@@ -377,7 +389,7 @@ TEST 27: Setting integers to arbitrary values globally
 330
 ============================================================
 ============================================================
-TEST 28: Subtract from integers
+TEST 29: Subtract from integers
 ============================================================
 -8
 2
@@ -387,7 +399,7 @@ TEST 28: Subtract from integers
 0
 ============================================================
 ============================================================
-TEST 29: Subtract from integers globally
+TEST 30: Subtract from integers globally
 ============================================================
 -8
 2
@@ -397,7 +409,7 @@ TEST 29: Subtract from integers globally
 4
 ============================================================
 ============================================================
-TEST 30: Zeroing integers
+TEST 31: Zeroing integers
 ============================================================
 0
 1234
@@ -405,7 +417,7 @@ TEST 30: Zeroing integers
 1234
 ============================================================
 ============================================================
-TEST 31: Zeroing integers globally
+TEST 32: Zeroing integers globally
 ============================================================
 0
 0
@@ -413,13 +425,13 @@ TEST 31: Zeroing integers globally
 0
 ============================================================
 ============================================================
-TEST 32: Integer variable overflows
+TEST 33: Integer variable overflows
 ============================================================
 -2147483648
 2147483647
 ============================================================
 ============================================================
-TEST 33: Showing integers
+TEST 34: Showing integers
 ============================================================
 > \l_A_int=123.
 <recently read> }
@@ -432,13 +444,13 @@ l. ...}
 l. ...}
 ============================================================
 ============================================================
-TEST 34: Using integers
+TEST 35: Using integers
 ============================================================
 123
 678
 ============================================================
 ============================================================
-TEST 35: Integer conversion to Arabic
+TEST 36: Integer conversion to Arabic
 ============================================================
 ! Missing number, treated as zero.
 <to be read again> 
@@ -454,7 +466,7 @@ look up `weird error' in the index to The TeXbook.)
 [0a\__int_eval_end: ]
 ============================================================
 ============================================================
-TEST 36: Integer conversion to alph
+TEST 37: Integer conversion to alph
 ============================================================
 []
 b
@@ -470,7 +482,7 @@ CU
 FXSHRXW
 ============================================================
 ============================================================
-TEST 37: Integer conversion to binary
+TEST 38: Integer conversion to binary
 ============================================================
 0
 10
@@ -480,7 +492,7 @@ TEST 37: Integer conversion to binary
 1111111111111111111111111111111
 ============================================================
 ============================================================
-TEST 38: Integer conversion to hexadecimal
+TEST 39: Integer conversion to hexadecimal
 ============================================================
 0
 2
@@ -498,7 +510,7 @@ C
 7FFFFFFF
 ============================================================
 ============================================================
-TEST 39: Integer conversion to octal
+TEST 40: Integer conversion to octal
 ============================================================
 0
 2
@@ -509,7 +521,7 @@ TEST 39: Integer conversion to octal
 17777777777
 ============================================================
 ============================================================
-TEST 40: Integer conversion to Roman numerals
+TEST 41: Integer conversion to Roman numerals
 ============================================================
 []
 ii
@@ -523,7 +535,7 @@ XCIX
 []
 ============================================================
 ============================================================
-TEST 41: Integers from alph
+TEST 42: Integers from alph
 ============================================================
 26
 731
@@ -532,14 +544,14 @@ TEST 41: Integers from alph
 731
 ============================================================
 ============================================================
-TEST 42: Integers from binary
+TEST 43: Integers from binary
 ============================================================
 21
 31
 -26
 ============================================================
 ============================================================
-TEST 43: Integers from hexadecimal
+TEST 44: Integers from hexadecimal
 ============================================================
 217059
 16777215
@@ -547,14 +559,14 @@ TEST 43: Integers from hexadecimal
 -53
 ============================================================
 ============================================================
-TEST 44: Integers from octal
+TEST 45: Integers from octal
 ============================================================
 227
 5349
 -29
 ============================================================
 ============================================================
-TEST 45: Integers from Roman numerals
+TEST 46: Integers from Roman numerals
 ============================================================
 1992
 3391
@@ -562,7 +574,7 @@ TEST 45: Integers from Roman numerals
 17
 ============================================================
 ============================================================
-TEST 46: Conversion of an integer to an arbitrary base
+TEST 47: Conversion of an integer to an arbitrary base
 ============================================================
 234
 121
@@ -574,7 +586,7 @@ TEST 46: Conversion of an integer to an arbitrary base
 1A
 ============================================================
 ============================================================
-TEST 47: Conversion of an integer from an arbitrary base
+TEST 48: Conversion of an integer from an arbitrary base
 ============================================================
 66
 81
@@ -582,18 +594,18 @@ TEST 47: Conversion of an integer from an arbitrary base
 210
 ============================================================
 ============================================================
-TEST 48: Public integer constants
+TEST 49: Public integer constants
 ============================================================
 2147483647
 ============================================================
 ============================================================
-TEST 49: Internal integer constants
+TEST 50: Internal integer constants
 ============================================================
 0
 1
 ============================================================
 ============================================================
-TEST 50: Integer while-do and do-while
+TEST 51: Integer while-do and do-while
 ============================================================
 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
 ============================================================
@@ -603,7 +615,7 @@ TEST 50: Integer while-do and do-while
 [10]
 ============================================================
 ============================================================
-TEST 51: Integer until-do and do-until
+TEST 52: Integer until-do and do-until
 ============================================================
 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
 ============================================================





More information about the latex3-commits mailing list.