* tests/qnan.h: New file, based on tests/totalorder.c.
* tests/nan.h: Add double-inclusion guard.
* tests/test-signbit.c: Include qnan.h.
(test_signbitf, test_signbitd, test_signbitl): Simplify.
* tests/test-totalorder.c: Include qnan.h instead of NaN.h.
(TOTALORDER_NAN): Remove macro.
(TOTALORDER_POSITIVE_NAN, TOTALORDER_NEGATIVE_NAN): New macros.
(positive_nan, negative_nan): Remove functions.
(main): Update.
* tests/test-totalorderf.c (TOTALORDER_NAN): Remove macro.
(TOTALORDER_POSITIVE_NAN, TOTALORDER_NEGATIVE_NAN): New macros.
* tests/test-totalorderl.c (TOTALORDER_NAN): Remove macro.
(TOTALORDER_POSITIVE_NAN, TOTALORDER_NEGATIVE_NAN): New macros.
* modules/signbit-tests (Files): Add tests/nan.h, tests/qnan.h.
* modules/totalorder-tests (Files): Add tests/qnan.h.
(Depends-on): Add signbit.
* modules/totalorderf-tests (Files): Add tests/qnan.h.
(Depends-on): Add signbit.
* modules/totalorderl-tests (Files): Add tests/qnan.h.
(Depends-on): Add signbit.
+2023-10-07 Bruno Haible <bruno@clisp.org>
+
+ tests: Refactor functions for quiet NaNs.
+ * tests/qnan.h: New file, based on tests/totalorder.c.
+ * tests/nan.h: Add double-inclusion guard.
+ * tests/test-signbit.c: Include qnan.h.
+ (test_signbitf, test_signbitd, test_signbitl): Simplify.
+ * tests/test-totalorder.c: Include qnan.h instead of NaN.h.
+ (TOTALORDER_NAN): Remove macro.
+ (TOTALORDER_POSITIVE_NAN, TOTALORDER_NEGATIVE_NAN): New macros.
+ (positive_nan, negative_nan): Remove functions.
+ (main): Update.
+ * tests/test-totalorderf.c (TOTALORDER_NAN): Remove macro.
+ (TOTALORDER_POSITIVE_NAN, TOTALORDER_NEGATIVE_NAN): New macros.
+ * tests/test-totalorderl.c (TOTALORDER_NAN): Remove macro.
+ (TOTALORDER_POSITIVE_NAN, TOTALORDER_NEGATIVE_NAN): New macros.
+ * modules/signbit-tests (Files): Add tests/nan.h, tests/qnan.h.
+ * modules/totalorder-tests (Files): Add tests/qnan.h.
+ (Depends-on): Add signbit.
+ * modules/totalorderf-tests (Files): Add tests/qnan.h.
+ (Depends-on): Add signbit.
+ * modules/totalorderl-tests (Files): Add tests/qnan.h.
+ (Depends-on): Add signbit.
+
2023-10-07 Bruno Haible <bruno@clisp.org>
totalorder*: Fix compilation error on glibc 2.25..2.30.
tests/test-signbit.c
tests/minus-zero.h
tests/infinity.h
+tests/nan.h
+tests/qnan.h
tests/macros.h
m4/exponentf.m4
m4/exponentd.m4
tests/minus-zero.h
tests/infinity.h
tests/nan.h
+tests/qnan.h
tests/macros.h
Depends-on:
+signbit
configure.ac:
tests/minus-zero.h
tests/infinity.h
tests/nan.h
+tests/qnan.h
tests/macros.h
Depends-on:
+signbit
configure.ac:
tests/minus-zero.h
tests/infinity.h
tests/nan.h
+tests/qnan.h
tests/macros.h
Depends-on:
+signbit
configure.ac:
-/* Macros for not-a-number.
+/* Macros for quiet not-a-number.
Copyright (C) 2007-2023 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
+#ifndef _TESTS_NAN_H
+#define _TESTS_NAN_H
+
/* IBM z/OS supports both hexadecimal and IEEE floating-point formats. The
former does not support NaN and its isnan() implementation returns zero
#else
# define NaNl() (0.0L / 0.0L)
#endif
+
+
+#endif /* _TESTS_NAN_H */
--- /dev/null
+/* Macros for quiet not-a-number.
+ Copyright (C) 2023 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <math.h>
+
+#include "nan.h"
+
+
+/* Returns a quiet 'float' NaN with sign bit == 0. */
+_GL_UNUSED static float
+positive_NaNf ()
+{
+ /* 'volatile' works around a GCC bug:
+ <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
+ float volatile nan = NaNf ();
+ return (signbit (nan) ? - nan : nan);
+}
+
+/* Returns a quiet 'float' NaN with sign bit == 1. */
+_GL_UNUSED static float
+negative_NaNf ()
+{
+ /* 'volatile' works around a GCC bug:
+ <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
+ float volatile nan = NaNf ();
+ return (signbit (nan) ? nan : - nan);
+}
+
+
+/* Returns a quiet 'double' NaN with sign bit == 0. */
+_GL_UNUSED static double
+positive_NaNd ()
+{
+ /* 'volatile' works around a GCC bug:
+ <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
+ double volatile nan = NaNd ();
+ return (signbit (nan) ? - nan : nan);
+}
+
+/* Returns a quiet 'double' NaN with sign bit == 1. */
+_GL_UNUSED static double
+negative_NaNd ()
+{
+ /* 'volatile' works around a GCC bug:
+ <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
+ double volatile nan = NaNd ();
+ return (signbit (nan) ? nan : - nan);
+}
+
+
+/* Returns a quiet 'long double' NaN with sign bit == 0. */
+_GL_UNUSED static long double
+positive_NaNl ()
+{
+ /* 'volatile' works around a GCC bug:
+ <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
+ long double volatile nan = NaNl ();
+ return (signbit (nan) ? - nan : nan);
+}
+
+/* Returns a quiet 'long double' NaN with sign bit == 1. */
+_GL_UNUSED static long double
+negative_NaNl ()
+{
+ /* 'volatile' works around a GCC bug:
+ <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
+ long double volatile nan = NaNl ();
+ return (signbit (nan) ? nan : - nan);
+}
#include "minus-zero.h"
#include "infinity.h"
+#include "qnan.h"
#include "macros.h"
float zerof = 0.0f;
ASSERT (!signbit (Infinityf ()));
ASSERT (signbit (- Infinityf ()));
/* Quiet NaN. */
- {
- float nan = zerof / zerof;
- float pos_nan;
- float neg_nan;
- if (signbit (nan))
- pos_nan = - nan, neg_nan = nan;
- else
- pos_nan = nan, neg_nan = - nan;
- ASSERT (!signbit (pos_nan));
- ASSERT (signbit (neg_nan));
- }
+ ASSERT (!signbit (positive_NaNf ()));
+ ASSERT (signbit (negative_NaNf ()));
#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
/* Signalling NaN. */
{
ASSERT (!signbit (Infinityd ()));
ASSERT (signbit (- Infinityd ()));
/* Quiet NaN. */
- {
- double nan = zerod / zerod;
- double pos_nan;
- double neg_nan;
- if (signbit (nan))
- pos_nan = - nan, neg_nan = nan;
- else
- pos_nan = nan, neg_nan = - nan;
- ASSERT (!signbit (pos_nan));
- ASSERT (signbit (neg_nan));
- }
+ ASSERT (!signbit (positive_NaNd ()));
+ ASSERT (signbit (negative_NaNd ()));
#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
/* Signalling NaN. */
{
ASSERT (!signbit (Infinityl ()));
ASSERT (signbit (- Infinityl ()));
/* Quiet NaN. */
- {
- long double nan = zerol / zerol;
- long double pos_nan;
- long double neg_nan;
- if (signbit (nan))
- pos_nan = - nan, neg_nan = nan;
- else
- pos_nan = nan, neg_nan = - nan;
- ASSERT (!signbit (pos_nan));
- ASSERT (signbit (neg_nan));
- }
+ ASSERT (!signbit (positive_NaNl ()));
+ ASSERT (signbit (negative_NaNl ()));
#if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
/* Signalling NaN. */
{
#include "infinity.h"
#include "macros.h"
#include "minus-zero.h"
-#include "nan.h"
+#include "qnan.h"
#ifndef TOTALORDER
# define TOTALORDER totalorder
# define TOTALORDER_INF Infinityd
# define TOTALORDER_MINUS_ZERO minus_zerod
-# define TOTALORDER_NAN NaNd
+# define TOTALORDER_POSITIVE_NAN positive_NaNd
+# define TOTALORDER_NEGATIVE_NAN negative_NaNd
# define TOTALORDER_TYPE double
#endif
-/* Return a quiet NaN with sign bit == 0. */
-static TOTALORDER_TYPE
-positive_nan ()
-{
- /* 'volatile' works around a GCC bug:
- <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
- TOTALORDER_TYPE volatile nan = TOTALORDER_NAN ();
- return (signbit (nan) ? - nan : nan);
-}
-
-/* Return a quiet NaN with sign bit == 1. */
-static TOTALORDER_TYPE
-negative_nan ()
-{
- /* 'volatile' works around a GCC bug:
- <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
- TOTALORDER_TYPE volatile nan = TOTALORDER_NAN ();
- return (signbit (nan) ? nan : - nan);
-}
-
int
main ()
{
TOTALORDER_TYPE x[] =
{
- negative_nan (), -TOTALORDER_INF (), -1e37, -1, -1e-5,
+ TOTALORDER_NEGATIVE_NAN (), -TOTALORDER_INF (), -1e37, -1, -1e-5,
TOTALORDER_MINUS_ZERO, 0,
- 1e-5, 1, 1e37, TOTALORDER_INF (), positive_nan ()
+ 1e-5, 1, 1e37, TOTALORDER_INF (), TOTALORDER_POSITIVE_NAN ()
};
int n = sizeof x / sizeof *x;
#define TOTALORDER totalorderf
#define TOTALORDER_INF Infinityf
#define TOTALORDER_MINUS_ZERO minus_zerof
-#define TOTALORDER_NAN NaNf
+#define TOTALORDER_POSITIVE_NAN positive_NaNf
+#define TOTALORDER_NEGATIVE_NAN negative_NaNf
#define TOTALORDER_TYPE float
#include "test-totalorder.c"
#define TOTALORDER totalorderl
#define TOTALORDER_INF Infinityl
#define TOTALORDER_MINUS_ZERO minus_zerol
-#define TOTALORDER_NAN NaNl
+#define TOTALORDER_POSITIVE_NAN positive_NaNl
+#define TOTALORDER_NEGATIVE_NAN negative_NaNl
#define TOTALORDER_TYPE long double
#include "test-totalorder.c"