[latex3-commits] [git/LaTeX3-latex3-latex3] master: Implement \int_sign:n that returns 1 or 0 or -1 (957f576)
Bruno Le Floch
bruno at le-floch.fr
Sat Nov 3 16:36:19 CET 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/957f576c0e8a42100c0054d883469f7c01e94289
>---------------------------------------------------------------
commit 957f576c0e8a42100c0054d883469f7c01e94289
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Sat Nov 3 16:36:19 2018 +0100
Implement \int_sign:n that returns 1 or 0 or -1
>---------------------------------------------------------------
957f576c0e8a42100c0054d883469f7c01e94289
l3kernel/l3candidates.dtx | 41 +++++++++++++++++++++++++++++++
l3kernel/testfiles/m3expl001.luatex.tlg | 2 ++
l3kernel/testfiles/m3expl001.ptex.tlg | 2 ++
l3kernel/testfiles/m3expl001.tlg | 2 ++
l3kernel/testfiles/m3expl001.uptex.tlg | 2 ++
l3kernel/testfiles/m3expl001.xetex.tlg | 2 ++
l3kernel/testfiles/m3expl003.luatex.tlg | 2 ++
l3kernel/testfiles/m3expl003.ptex.tlg | 2 ++
l3kernel/testfiles/m3expl003.tlg | 2 ++
l3kernel/testfiles/m3expl003.uptex.tlg | 2 ++
l3kernel/testfiles/m3expl003.xetex.tlg | 2 ++
l3kernel/testfiles/m3int003.lvt | 7 +++++-
l3kernel/testfiles/m3int003.tlg | 7 +++++-
13 files changed, 73 insertions(+), 2 deletions(-)
diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index f37e031..adaf98a 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -421,6 +421,14 @@
% This is not yet available in \XeTeX{}.
% \end{function}
%
+% \begin{function}[EXP, added = 2018-11-03]{\int_sign:n}
+% \begin{syntax}
+% \cs{int_sign:n} \Arg{intexpr}
+% \end{syntax}
+% Evaluates the \meta{integer expression} then leaves $1$ or $0$ or
+% $-1$ in the input stream according to the sign of the result.
+% \end{function}
+%
% \section{Additions to \pkg{l3intarray}}
%
% \begin{function}[EXP, added = 2018-05-05]{\intarray_rand_item:N}
@@ -2310,6 +2318,39 @@
% \subsection{Additions to \pkg{l3msg}}
%
% \begin{macrocode}
+%<@@=int>
+% \end{macrocode}
+%
+% \begin{macro}[EXP]{\int_sign:n, \@@_sign:Nw}
+% See \cs{int_abs:n}. Evaluate the expression once (and when
+% debugging is enabled, check that the expression is well-formed),
+% then test the first character to determine the sign. This is
+% wrapped in \cs{int_value:w} \ldots{} \cs{exp_stop_f:} to ensure a
+% fixed number of expansions and to avoid dealing with closing the
+% conditionals.
+% \begin{macrocode}
+\__kernel_patch_args:nNNpn
+ { { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_sign:n } }
+\cs_new:Npn \int_sign:n #1
+ {
+ \int_value:w \exp_after:wN \@@_sign:Nw
+ \int_value:w \@@_eval:w #1 \@@_eval_end: ;
+ \exp_stop_f:
+ }
+\cs_new:Npn \@@_sign:Nw #1#2 ;
+ {
+ \if_meaning:w 0 #1
+ 0
+ \else:
+ \if_meaning:w - #1 - \fi: 1
+ \fi:
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Additions to \pkg{l3msg}}
+%
+% \begin{macrocode}
%<@@=msg>
% \end{macrocode}
%
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 60ca59a..8cf468b 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -5787,6 +5787,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 14d0648..f75482a 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -5820,6 +5820,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index d416b7b..cb6fae2 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -5820,6 +5820,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 55acef8..820d194 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -5817,6 +5817,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 08c102c..2b63698 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -5798,6 +5798,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 60ca59a..8cf468b 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -5787,6 +5787,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 14d0648..f75482a 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -5820,6 +5820,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index d416b7b..cb6fae2 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -5820,6 +5820,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 55acef8..820d194 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -5817,6 +5817,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 08c102c..2b63698 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -5798,6 +5798,8 @@ Defining \file_if_exist_input:n on line ...
Defining \file_if_exist_input:nF on line ...
Defining \file_input_stop: on line ...
Defining \flag_raise_if_clear:n on line ...
+Defining \int_sign:n on line ...
+Defining \__int_sign:Nw on line ...
Defining \msg_expandable_error:nnnnnn on line ...
Defining \msg_expandable_error:nnnnn on line ...
Defining \msg_expandable_error:nnnn on line ...
diff --git a/l3kernel/testfiles/m3int003.lvt b/l3kernel/testfiles/m3int003.lvt
index 0474fe8..0ba58a8 100644
--- a/l3kernel/testfiles/m3int003.lvt
+++ b/l3kernel/testfiles/m3int003.lvt
@@ -33,7 +33,7 @@
\test:n { \int_eval:n {-4+3} } \NEWLINE
}
-\TESTEXP{max/min/abs}{
+\TESTEXP{max/min/abs/sign}{
\test:n { \int_max:nn {0} {0} } \NEWLINE
\test:n { \int_max:nn {-999} {0} } \NEWLINE
\test:n { \int_max:nn {-999} {-5+6} } \NEWLINE
@@ -48,6 +48,11 @@
\test:n { \int_abs:n {-7} } = 7 \NEWLINE
\test:n { \int_abs:n {-15+30} } = 15 \NEWLINE
\test:n { \int_abs:n {-15-30} } = 45 \NEWLINE
+ === \NEWLINE
+ \test:n { \int_sign:n {-0} } = 0 \NEWLINE
+ \test:n { \int_sign:n {-7} } = -1 \NEWLINE
+ \test:n { \int_sign:n {-15+30} } = 1 \NEWLINE
+ \test:n { \int_sign:n {-15-30} } = -1 \NEWLINE
}
\TESTEXP{div_truncate/div_round/mod}{
diff --git a/l3kernel/testfiles/m3int003.tlg b/l3kernel/testfiles/m3int003.tlg
index 27291d9..f56f8cc 100644
--- a/l3kernel/testfiles/m3int003.tlg
+++ b/l3kernel/testfiles/m3int003.tlg
@@ -38,7 +38,7 @@ TEST 2: eval
-1
============================================================
============================================================
-TEST 3: max/min/abs
+TEST 3: max/min/abs/sign
============================================================
0
0
@@ -54,6 +54,11 @@ TEST 3: max/min/abs
7=7
15=15
45=45
+===
+0=0
+-1=-1
+1=1
+-1=-1
============================================================
============================================================
TEST 4: div_truncate/div_round/mod
More information about the latex3-commits
mailing list