[latex3-commits] [git/LaTeX3-latex3-latex3] master: Make comparison work for tuples (c199f6d)

Bruno Le Floch bruno at le-floch.fr
Sun Feb 25 21:01:13 CET 2018


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

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

commit c199f6dc2a34492f58353618e322282f8db9b101
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sun Feb 25 12:20:15 2018 -0500

    Make comparison work for tuples


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

c199f6dc2a34492f58353618e322282f8db9b101
 l3kernel/l3fp-logic.dtx                 |   65 +++++++++++++++++++++++++++++--
 l3kernel/l3fp-parse.dtx                 |    2 +-
 l3kernel/testfiles/m3expl001.luatex.tlg |    5 +++
 l3kernel/testfiles/m3expl001.ptex.tlg   |    5 +++
 l3kernel/testfiles/m3expl001.tlg        |    5 +++
 l3kernel/testfiles/m3expl001.uptex.tlg  |    5 +++
 l3kernel/testfiles/m3expl001.xetex.tlg  |    5 +++
 l3kernel/testfiles/m3expl003.luatex.tlg |    5 +++
 l3kernel/testfiles/m3expl003.ptex.tlg   |    5 +++
 l3kernel/testfiles/m3expl003.tlg        |    5 +++
 l3kernel/testfiles/m3expl003.uptex.tlg  |    5 +++
 l3kernel/testfiles/m3expl003.xetex.tlg  |    5 +++
 l3kernel/testfiles/m3fp-logic001.lvt    |   12 +++++-
 l3kernel/testfiles/m3fp-logic001.tlg    |   42 +++++++++++++++++++-
 14 files changed, 164 insertions(+), 7 deletions(-)

diff --git a/l3kernel/l3fp-logic.dtx b/l3kernel/l3fp-logic.dtx
index 558097b..3a50e9b 100644
--- a/l3kernel/l3fp-logic.dtx
+++ b/l3kernel/l3fp-logic.dtx
@@ -118,7 +118,7 @@
 % \begin{macro}[pTF, EXP]{\fp_compare:nNn}
 % \begin{macro}[EXP]{\@@_compare_aux:wn}
 %   Evaluate |#1| and |#3|, using an auxiliary to expand both, and feed
-%   the two floating point numbers swapped to \cs{@@_compare_back:ww},
+%   the two floating point numbers swapped to \cs{@@_compare_back_any:ww},
 %   defined below.  Compare the result with |`#2-`=|, which is $-1$ for
 %   |<|, $0$ for |=|, $1$ for |>| and $2$ for |?|.
 %    \begin{macrocode}
@@ -135,16 +135,16 @@
   }
 \cs_new:Npn \@@_compare_aux:wn #1; #2
   {
-    \exp_after:wN \@@_compare_back:ww
+    \exp_after:wN \@@_compare_back_any:ww
       \exp:w \exp_end_continue_f:w \@@_parse:n {#2} #1;
   }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
 %
-% \begin{macro}[EXP]{\@@_compare_back:ww, \@@_compare_nan:w}
+% \begin{macro}[EXP]{\@@_compare_back_any:ww, \@@_compare_back:ww, \@@_compare_nan:w}
 %   \begin{quote}
-%     \cs{@@_compare_back:ww} \meta{y} |;| \meta{x} |;|
+%     \cs{@@_compare_back_any:ww} \meta{y} |;| \meta{x} |;|
 %   \end{quote}
 %   Expands (in the same way as \cs{int_eval:n}) to $-1$ if $x<y$, $0$
 %   if $x=y$, $1$ if $x>y$, and $2$ otherwise (denoted as $x?y$).  If
@@ -157,6 +157,23 @@
 %   a different type, the highest type is a larger number.  Finally, if
 %   $y\leq 0$, then $x>y$, unless both are zero.
 %    \begin{macrocode}
+\cs_new:Npn \@@_compare_back_any:ww #1#2; #3
+  {
+    \@@_if_type_fp:NTwFw
+      #1 { \@@_if_type_fp:NTwFw #3 \use_i:nn \s_@@ \use_ii:nn \q_stop }
+      \s_@@ \use_ii:nn \q_stop
+    \@@_compare_back:ww
+    {
+      \cs:w
+        @@
+        \@@_type_from_scan:N #1
+        _compare_back
+        \@@_type_from_scan:N #3
+        :ww
+      \cs_end:
+    }
+    #1#2 ; #3
+  }
 \cs_new:Npn \@@_compare_back:ww
     \s_@@ \@@_chk:w #1 #2 #3;
     \s_@@ \@@_chk:w #4 #5 #6;
@@ -188,6 +205,46 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}[EXP]{\@@_compare_back_tuple:ww, \@@_tuple_compare_back:ww, \@@_tuple_compare_back_tuple:ww}
+% \begin{macro}[EXP]{\@@_tuple_compare_back_loop:w}
+%   Tuple and floating point numbers are not comparable so return $2$ in
+%   mixed cases or when tuples have a different number of items.
+%   Otherwise compare pairs of items with \cs{@@_compare_back_any:ww}
+%   and if any don't match return~$2$ (as \cs{__int_value:w} |02|
+%   \cs{exp_stop_f:}).
+%    \begin{macrocode}
+\cs_new:Npn \@@_compare_back_tuple:ww #1; #2; { 2 }
+\cs_new:Npn \@@_tuple_compare_back:ww #1; #2; { 2 }
+\cs_new:Npn \@@_tuple_compare_back_tuple:ww
+  \s_@@_tuple \@@_tuple_chk:w #1;
+  \s_@@_tuple \@@_tuple_chk:w #2;
+  {
+    \int_compare:nNnTF { \@@_array_count:n {#1} } = { \@@_array_count:n {#2} }
+      {
+        \__int_value:w 0
+          \@@_tuple_compare_back_loop:w
+              #1 { \s_@@ \__prg_break: } ; @
+              #2 { \s_@@ \__prg_break: } ;
+            \__prg_break_point:
+        \exp_stop_f:
+      }
+      { 2 }
+  }
+\cs_new:Npn \@@_tuple_compare_back_loop:w #1#2 ; #3 @ #4#5 ;
+  {
+    \use_none:n #1
+    \use_none:n #4
+    \if_int_compare:w
+        \@@_compare_back_any:ww #1 #2 ; #4 #5 ; = 0 \exp_stop_f:
+    \else:
+      2 \exp_after:wN \__prg_break:
+    \fi:
+    \@@_tuple_compare_back_loop:w #3 @
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \begin{macro}[EXP]{\@@_compare_npos:nwnw}
 % \begin{macro}[EXP]{\@@_compare_significand:nnnnnnnn}
 %   \begin{quote}
diff --git a/l3kernel/l3fp-parse.dtx b/l3kernel/l3fp-parse.dtx
index 4d8fba7..a94f990 100644
--- a/l3kernel/l3fp-parse.dtx
+++ b/l3kernel/l3fp-parse.dtx
@@ -2602,7 +2602,7 @@
         \if_meaning:w \c_zero_fp #3
           0
         \else:
-          \if_case:w \@@_compare_back:ww #8 #2 \exp_stop_f:
+          \if_case:w \@@_compare_back_any:ww #8 #2 \exp_stop_f:
             #5 \or: #6 \or: #7 \else: #4
           \fi:
         \fi:
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 4726754..55fd9e8 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -4060,8 +4060,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 6de67ce..9e1fea9 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -4048,8 +4048,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index e85f323..75273d8 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -4048,8 +4048,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 2ff99e8..f1cd87d 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -4048,8 +4048,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index a21353d..e531f97 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -4058,8 +4058,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 4726754..55fd9e8 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -4060,8 +4060,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 6de67ce..9e1fea9 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -4048,8 +4048,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index e85f323..75273d8 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -4048,8 +4048,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 2ff99e8..f1cd87d 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -4048,8 +4048,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index a21353d..e531f97 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -4058,8 +4058,13 @@ Defining \fp_compare:nNnT on line ...
 Defining \fp_compare:nNnF on line ...
 Defining \fp_compare:nNnTF on line ...
 Defining \__fp_compare_aux:wn on line ...
+Defining \__fp_compare_back_any:ww on line ...
 Defining \__fp_compare_back:ww on line ...
 Defining \__fp_compare_nan:w on line ...
+Defining \__fp_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back:ww on line ...
+Defining \__fp_tuple_compare_back_tuple:ww on line ...
+Defining \__fp_tuple_compare_back_loop:w on line ...
 Defining \__fp_compare_npos:nwnw on line ...
 Defining \__fp_compare_significand:nnnnnnnn on line ...
 Defining \fp_do_until:nn on line ...
diff --git a/l3kernel/testfiles/m3fp-logic001.lvt b/l3kernel/testfiles/m3fp-logic001.lvt
index c1c00fc..c63b99f 100644
--- a/l3kernel/testfiles/m3fp-logic001.lvt
+++ b/l3kernel/testfiles/m3fp-logic001.lvt
@@ -1,5 +1,5 @@
 %
-% Copyright (C) 2012 LaTeX3 Project
+% Copyright (C) 2012,2018 LaTeX3 Project
 %
 
 \documentclass{minimal}
@@ -127,6 +127,16 @@
     \test:nn {1} {-1}
   }
 
+\TESTEXP { Comparing~tuples }
+  {
+    \test:nn {1} {()}
+    \test:nn {()} {1}
+    \test:nn {(1,-0)} {()}
+    \test:nn {(1,-0)} {(1,+0)}
+    \test:nn {(1,nan)} {(1,nan)}
+    \test:nn {(2,3)} {(4,5)}
+  }
+
 \TESTEXP { Expansion~and~expressions }
   {
     \fp_to_tl:n { ( 2 = ~ \use_none:n { > } ? nan ) * 3 } \NEWLINE
diff --git a/l3kernel/testfiles/m3fp-logic001.tlg b/l3kernel/testfiles/m3fp-logic001.tlg
index 2e83d38..ef0be0e 100644
--- a/l3kernel/testfiles/m3fp-logic001.tlg
+++ b/l3kernel/testfiles/m3fp-logic001.tlg
@@ -273,7 +273,47 @@ TEST 2: Comparing normal floating points
 !<  TRUE  TRUE FALSE FALSE  TRUE  TRUE FALSE FALSE
 ============================================================
 ============================================================
-TEST 3: Expansion and expressions
+TEST 3: Comparing tuples
+============================================================
+1 and ()
+            ?    >     >?   =     = ?   =>    =>? 
+   FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+ < FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+!   TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+!<  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+() and 1
+            ?    >     >?   =     = ?   =>    =>? 
+   FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+ < FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+!   TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+!<  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+(1, -0) and ()
+            ?    >     >?   =     = ?   =>    =>? 
+   FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+ < FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+!   TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+!<  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+(1, -0) and (1, 0)
+            ?    >     >?   =     = ?   =>    =>? 
+   FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE
+ < FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE
+!   TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
+!<  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
+(1, nan) and (1, nan)
+            ?    >     >?   =     = ?   =>    =>? 
+   FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+ < FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+!   TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+!<  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+(2, 3) and (4, 5)
+            ?    >     >?   =     = ?   =>    =>? 
+   FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+ < FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
+!   TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+!<  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
+============================================================
+============================================================
+TEST 4: Expansion and expressions
 ============================================================
 3
 0





More information about the latex3-commits mailing list