In the specification of totalorder* [1] we read: "in the following order: - negative quiet NaNs, in order of decreasing payload; - negative signaling NaNs, in order of decreasing payload; - negative infinity; - finite numbers, in ascending order, with negative zero before positive zero; - positive infinity; - positive signaling NaNs, in order of increasing payload; - positive quiet NaNs, in order of increasing payload."
With the setpayload{,f,l} functions, it is possible to test the cases - negative quiet NaNs, in order of decreasing payload; and - positive quiet NaNs, in order of increasing payload. The patch below does this. (With the setpayloadsig* functions it would also be possible to test the case - positive signaling NaNs, in order of increasing payload; However, the case - negative signaling NaNs, in order of decreasing payload; is harder, because we have no ISO C function for creating a negative signalling NaN with given payload.) [1] https://www.gnu.org/software/libc/manual/html_node/FP-Comparison-Functions.html 2024-04-17 Bruno Haible <br...@clisp.org> totalorder* tests: Strengthen tests. * tests/test-totalorder.h: Include <math.h>. (positive_NaN_with_payload, negative_NaN_with_payload): New functions. (main): Test quiet NaNs of each sign with different payload. * tests/test-totalorder.c (TOTALORDER_POSITIVE_NAN, TOTALORDER_NEGATIVE_NAN): Remove macros. (TOTALORDER_SETPAYLOAD): New macro. * tests/test-totalorderf.c (TOTALORDER_POSITIVE_NAN, TOTALORDER_NEGATIVE_NAN): Remove macros. (TOTALORDER_SETPAYLOAD): New macro. * tests/test-totalorderl.c (TOTALORDER_POSITIVE_NAN, TOTALORDER_NEGATIVE_NAN): Remove macros. (TOTALORDER_SETPAYLOAD): New macro. * modules/totalorder-tests (Depends-on): Add setpayload. (Makefile.am): Link test-totalorder with $(SETPAYLOAD_LIBM). * modules/totalorderf-tests (Depends-on): Add setpayloadf. (Makefile.am): Link test-totalorderf with $(SETPAYLOADF_LIBM). * modules/totalorderl-tests (Depends-on): Add setpayloadl. (Makefile.am): Link test-totalorderl with $(SETPAYLOADL_LIBM). diff --git a/modules/totalorder-tests b/modules/totalorder-tests index ca6238f7cb..6df07edfcf 100644 --- a/modules/totalorder-tests +++ b/modules/totalorder-tests @@ -9,10 +9,11 @@ tests/macros.h Depends-on: signed-nan signed-snan +setpayload configure.ac: Makefile.am: TESTS += test-totalorder check_PROGRAMS += test-totalorder -test_totalorder_LDADD = $(LDADD) @TOTALORDER_LIBM@ +test_totalorder_LDADD = $(LDADD) @TOTALORDER_LIBM@ $(SETPAYLOAD_LIBM) diff --git a/modules/totalorderf-tests b/modules/totalorderf-tests index dbca0add15..258cb9c0c2 100644 --- a/modules/totalorderf-tests +++ b/modules/totalorderf-tests @@ -9,10 +9,11 @@ tests/macros.h Depends-on: signed-nan signed-snan +setpayloadf configure.ac: Makefile.am: TESTS += test-totalorderf check_PROGRAMS += test-totalorderf -test_totalorderf_LDADD = $(LDADD) @TOTALORDERF_LIBM@ +test_totalorderf_LDADD = $(LDADD) @TOTALORDERF_LIBM@ $(SETPAYLOADF_LIBM) diff --git a/modules/totalorderl-tests b/modules/totalorderl-tests index ab73b6a5fd..222cc32992 100644 --- a/modules/totalorderl-tests +++ b/modules/totalorderl-tests @@ -9,10 +9,11 @@ tests/macros.h Depends-on: signed-nan signed-snan +setpayloadl configure.ac: Makefile.am: TESTS += test-totalorderl check_PROGRAMS += test-totalorderl -test_totalorderl_LDADD = $(LDADD) @TOTALORDERL_LIBM@ +test_totalorderl_LDADD = $(LDADD) @TOTALORDERL_LIBM@ $(SETPAYLOADL_LIBM) diff --git a/tests/test-totalorder.c b/tests/test-totalorder.c index 77926e4a5f..412c3d301e 100644 --- a/tests/test-totalorder.c +++ b/tests/test-totalorder.c @@ -26,8 +26,7 @@ SIGNATURE_CHECK (totalorder, int, (const double *, const double *)); #define TOTALORDER_TYPE memory_double #define TOTALORDER_INF Infinityd #define TOTALORDER_MINUS_ZERO minus_zerod -#define TOTALORDER_POSITIVE_NAN positive_NaNd -#define TOTALORDER_NEGATIVE_NAN negative_NaNd +#define TOTALORDER_SETPAYLOAD setpayload #define TOTALORDER_HAVE_SNAN HAVE_SNAND #define TOTALORDER_POSITIVE_SNAN memory_positive_SNaNd #define TOTALORDER_NEGATIVE_SNAN memory_negative_SNaNd diff --git a/tests/test-totalorder.h b/tests/test-totalorder.h index c82d112956..b02cec310b 100644 --- a/tests/test-totalorder.h +++ b/tests/test-totalorder.h @@ -16,18 +16,37 @@ #include <stdio.h> +#include <math.h> #include "infinity.h" #include "macros.h" #include "minus-zero.h" #include "signed-nan.h" #include "signed-snan.h" +static TOTALORDER_TYPE +positive_NaN_with_payload (int payload) +{ + TOTALORDER_TYPE x; + ASSERT (TOTALORDER_SETPAYLOAD (&x.value, payload) == 0); + return x; +} + +static TOTALORDER_TYPE +negative_NaN_with_payload (int payload) +{ + TOTALORDER_TYPE x; + ASSERT (TOTALORDER_SETPAYLOAD (&x.value, payload) == 0); + x.value = - x.value; + return x; +} + int main () { TOTALORDER_TYPE x[] = { - { TOTALORDER_NEGATIVE_NAN () }, + negative_NaN_with_payload (1729), + negative_NaN_with_payload (641), #if TOTALORDER_HAVE_SNAN TOTALORDER_NEGATIVE_SNAN (), #endif @@ -44,7 +63,8 @@ main () #if TOTALORDER_HAVE_SNAN TOTALORDER_POSITIVE_SNAN (), #endif - { TOTALORDER_POSITIVE_NAN () } + positive_NaN_with_payload (641), + positive_NaN_with_payload (1729) }; int n = SIZEOF (x); int result = 0; diff --git a/tests/test-totalorderf.c b/tests/test-totalorderf.c index 0094fad5c5..a3dd23a296 100644 --- a/tests/test-totalorderf.c +++ b/tests/test-totalorderf.c @@ -26,8 +26,7 @@ SIGNATURE_CHECK (totalorderf, int, (const float *, const float *)); #define TOTALORDER_TYPE memory_float #define TOTALORDER_INF Infinityf #define TOTALORDER_MINUS_ZERO minus_zerof -#define TOTALORDER_POSITIVE_NAN positive_NaNf -#define TOTALORDER_NEGATIVE_NAN negative_NaNf +#define TOTALORDER_SETPAYLOAD setpayloadf #define TOTALORDER_HAVE_SNAN HAVE_SNANF #define TOTALORDER_POSITIVE_SNAN memory_positive_SNaNf #define TOTALORDER_NEGATIVE_SNAN memory_negative_SNaNf diff --git a/tests/test-totalorderl.c b/tests/test-totalorderl.c index 74364ddd75..f3db8194f7 100644 --- a/tests/test-totalorderl.c +++ b/tests/test-totalorderl.c @@ -26,8 +26,7 @@ SIGNATURE_CHECK (totalorderl, int, (const long double *, const long double *)); #define TOTALORDER_TYPE memory_long_double #define TOTALORDER_INF Infinityl #define TOTALORDER_MINUS_ZERO minus_zerol -#define TOTALORDER_POSITIVE_NAN positive_NaNl -#define TOTALORDER_NEGATIVE_NAN negative_NaNl +#define TOTALORDER_SETPAYLOAD setpayloadl #define TOTALORDER_HAVE_SNAN HAVE_SNANL #define TOTALORDER_POSITIVE_SNAN memory_positive_SNaNl #define TOTALORDER_NEGATIVE_SNAN memory_negative_SNaNl