From: Bruno Haible Date: Thu, 12 Oct 2023 19:46:13 +0000 (+0200) Subject: snan: New module. X-Git-Tag: v1.0~721 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=815a9ce58a14afdff659a287ff4d55cbef7cf35d;p=gnulib.git snan: New module. * lib/snan.h: Renamed from tests/snan.h. Add double-inclusion guard. * modules/snan: New file. * isfinite-tests (Files): Remove tests/snan.h, m4/exponent*.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION, gl_DOUBLE_EXPONENT_LOCATION, gl_LONG_DOUBLE_EXPONENT_LOCATION. * isinf-tests (Files): Remove tests/snan.h, m4/exponent*.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION, gl_DOUBLE_EXPONENT_LOCATION, gl_LONG_DOUBLE_EXPONENT_LOCATION. * isnan-tests (Files): Remove tests/snan.h, m4/exponent*.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION, gl_DOUBLE_EXPONENT_LOCATION, gl_LONG_DOUBLE_EXPONENT_LOCATION. * isnanf-nolibm-tests (Files): Remove tests/snan.h, m4/exponentf.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION. * isnanf-tests (Files): Remove tests/snan.h, m4/exponentf.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION. * isnand-nolibm-tests (Files): Remove tests/snan.h, m4/exponentd.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_DOUBLE_EXPONENT_LOCATION. * isnand-tests (Files): Remove tests/snan.h, m4/exponentd.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_DOUBLE_EXPONENT_LOCATION. * isnanl-nolibm-tests (Files): Remove tests/snan.h, m4/exponentl.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_LONG_DOUBLE_EXPONENT_LOCATION. * isnanl-tests (Files): Remove tests/snan.h, m4/exponentl.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_LONG_DOUBLE_EXPONENT_LOCATION. * signbit-tests (Files): Remove tests/snan.h, m4/exponent*.m4. (Depends-on): Add snan. (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION, gl_DOUBLE_EXPONENT_LOCATION, gl_LONG_DOUBLE_EXPONENT_LOCATION. * stdio-tests (Files): Remove tests/snan.h (Depends-on): Add snan. --- diff --git a/ChangeLog b/ChangeLog index b072697e2a..ede627dca4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,45 @@ +2023-10-12 Bruno Haible + + snan: New module. + * lib/snan.h: Renamed from tests/snan.h. Add double-inclusion guard. + * modules/snan: New file. + * isfinite-tests (Files): Remove tests/snan.h, m4/exponent*.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION, + gl_DOUBLE_EXPONENT_LOCATION, gl_LONG_DOUBLE_EXPONENT_LOCATION. + * isinf-tests (Files): Remove tests/snan.h, m4/exponent*.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION, + gl_DOUBLE_EXPONENT_LOCATION, gl_LONG_DOUBLE_EXPONENT_LOCATION. + * isnan-tests (Files): Remove tests/snan.h, m4/exponent*.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION, + gl_DOUBLE_EXPONENT_LOCATION, gl_LONG_DOUBLE_EXPONENT_LOCATION. + * isnanf-nolibm-tests (Files): Remove tests/snan.h, m4/exponentf.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION. + * isnanf-tests (Files): Remove tests/snan.h, m4/exponentf.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION. + * isnand-nolibm-tests (Files): Remove tests/snan.h, m4/exponentd.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_DOUBLE_EXPONENT_LOCATION. + * isnand-tests (Files): Remove tests/snan.h, m4/exponentd.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_DOUBLE_EXPONENT_LOCATION. + * isnanl-nolibm-tests (Files): Remove tests/snan.h, m4/exponentl.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_LONG_DOUBLE_EXPONENT_LOCATION. + * isnanl-tests (Files): Remove tests/snan.h, m4/exponentl.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_LONG_DOUBLE_EXPONENT_LOCATION. + * signbit-tests (Files): Remove tests/snan.h, m4/exponent*.m4. + (Depends-on): Add snan. + (configure.ac): Don't invoke gl_FLOAT_EXPONENT_LOCATION, + gl_DOUBLE_EXPONENT_LOCATION, gl_LONG_DOUBLE_EXPONENT_LOCATION. + * stdio-tests (Files): Remove tests/snan.h + (Depends-on): Add snan. + 2023-10-12 Bruno Haible qnan: New module. diff --git a/lib/snan.h b/lib/snan.h new file mode 100644 index 0000000000..5dd4dd6f9e --- /dev/null +++ b/lib/snan.h @@ -0,0 +1,126 @@ +/* Macros for signalling not-a-number. + Copyright (C) 2007-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 . */ + +#ifndef _SNAN_H +#define _SNAN_H + +#include +#include +#include + +#include "nan.h" + + +#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT + +# define HAVE_SNANF 1 + +/* Returns a signalling 'float' NaN. */ +_GL_UNUSED static float +SNaNf () +{ + #define NWORDS \ + ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) + typedef union { float value; unsigned int word[NWORDS]; } memory_float; + memory_float m; + m.value = NaNf (); + #if FLT_EXPBIT0_BIT > 0 + m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1); + #else + m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] + ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1); + #endif + if (FLT_EXPBIT0_WORD < NWORDS / 2) + m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT; + else + m.word[0] |= (unsigned int) 1; + #undef NWORDS + return m.value; +} + +#endif + + +#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT + +# define HAVE_SNAND 1 + +/* Returns a signalling 'double' NaN. */ +_GL_UNUSED static double +SNaNd () +{ + #define NWORDS \ + ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) + typedef union { double value; unsigned int word[NWORDS]; } memory_double; + memory_double m; + m.value = NaNd (); + #if DBL_EXPBIT0_BIT > 0 + m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1); + #else + m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] + ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1); + #endif + m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] + |= (unsigned int) 1 << DBL_EXPBIT0_BIT; + #undef NWORDS + return m.value; +} + +#endif + + +#if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT + +# define HAVE_SNANL 1 + +/* Returns a signalling 'long double' NaN. */ +_GL_UNUSED static long double +SNaNl () +{ + /* A bit pattern that is different from a Quiet NaN. With a bit of luck, + it's a Signalling NaN. */ + #define NWORDS \ + ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) + typedef union { unsigned int word[NWORDS]; long double value; } + memory_long_double; + memory_long_double m; + m.value = NaNl (); + #if defined __powerpc__ && LDBL_MANT_DIG == 106 + /* This is PowerPC "double double", a pair of two doubles. Inf and NaN are + represented as the corresponding 64-bit IEEE values in the first double; + the second is ignored. Manipulate only the first double. */ + #define HNWORDS \ + ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) + #else + #define HNWORDS NWORDS + #endif + #if LDBL_EXPBIT0_BIT > 0 + m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1); + #else + m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < HNWORDS / 2 ? 1 : - 1)] + ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1); + #endif + m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < HNWORDS / 2 ? 1 : - 1)] + |= (unsigned int) 1 << LDBL_EXPBIT0_BIT; + #undef HNWORDS + #undef NWORDS + return m.value; +} + +#endif + + +#endif /* _SNAN_H */ diff --git a/modules/isfinite-tests b/modules/isfinite-tests index 16f4c8d187..5b316dd2ee 100644 --- a/modules/isfinite-tests +++ b/modules/isfinite-tests @@ -1,20 +1,14 @@ Files: tests/test-isfinite.c tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentf.m4 -m4/exponentd.m4 -m4/exponentl.m4 Depends-on: float nan +snan configure.ac: -gl_FLOAT_EXPONENT_LOCATION -gl_DOUBLE_EXPONENT_LOCATION -gl_LONG_DOUBLE_EXPONENT_LOCATION AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) Makefile.am: diff --git a/modules/isinf-tests b/modules/isinf-tests index caf77a88f9..0cae337cb2 100644 --- a/modules/isinf-tests +++ b/modules/isinf-tests @@ -1,20 +1,14 @@ Files: tests/test-isinf.c tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentf.m4 -m4/exponentd.m4 -m4/exponentl.m4 Depends-on: float nan +snan configure.ac: -gl_FLOAT_EXPONENT_LOCATION -gl_DOUBLE_EXPONENT_LOCATION -gl_LONG_DOUBLE_EXPONENT_LOCATION AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) Makefile.am: diff --git a/modules/isnan-tests b/modules/isnan-tests index 8da13c2349..f0d5280cf3 100644 --- a/modules/isnan-tests +++ b/modules/isnan-tests @@ -2,20 +2,14 @@ Files: tests/test-isnan.c tests/minus-zero.h tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentf.m4 -m4/exponentd.m4 -m4/exponentl.m4 Depends-on: float nan +snan configure.ac: -gl_FLOAT_EXPONENT_LOCATION -gl_DOUBLE_EXPONENT_LOCATION -gl_LONG_DOUBLE_EXPONENT_LOCATION AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) Makefile.am: diff --git a/modules/isnand-nolibm-tests b/modules/isnand-nolibm-tests index b4fa23e9d9..9a8569f966 100644 --- a/modules/isnand-nolibm-tests +++ b/modules/isnand-nolibm-tests @@ -3,15 +3,13 @@ tests/test-isnand-nolibm.c tests/test-isnand.h tests/minus-zero.h tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentd.m4 Depends-on: nan +snan configure.ac: -gl_DOUBLE_EXPONENT_LOCATION Makefile.am: TESTS += test-isnand-nolibm diff --git a/modules/isnand-tests b/modules/isnand-tests index 82f4d2e1dc..a3c8b564c2 100644 --- a/modules/isnand-tests +++ b/modules/isnand-tests @@ -3,15 +3,13 @@ tests/test-isnand.c tests/test-isnand.h tests/minus-zero.h tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentd.m4 Depends-on: nan +snan configure.ac: -gl_DOUBLE_EXPONENT_LOCATION Makefile.am: TESTS += test-isnand diff --git a/modules/isnanf-nolibm-tests b/modules/isnanf-nolibm-tests index 6dece6e5d9..3ceb3c14d9 100644 --- a/modules/isnanf-nolibm-tests +++ b/modules/isnanf-nolibm-tests @@ -3,15 +3,13 @@ tests/test-isnanf-nolibm.c tests/test-isnanf.h tests/minus-zero.h tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentf.m4 Depends-on: nan +snan configure.ac: -gl_FLOAT_EXPONENT_LOCATION Makefile.am: TESTS += test-isnanf-nolibm diff --git a/modules/isnanf-tests b/modules/isnanf-tests index 464618c2f9..f1d5213ba8 100644 --- a/modules/isnanf-tests +++ b/modules/isnanf-tests @@ -3,15 +3,13 @@ tests/test-isnanf.c tests/test-isnanf.h tests/minus-zero.h tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentf.m4 Depends-on: nan +snan configure.ac: -gl_FLOAT_EXPONENT_LOCATION Makefile.am: TESTS += test-isnanf diff --git a/modules/isnanl-nolibm-tests b/modules/isnanl-nolibm-tests index 88a4ddfc9c..c35806d6a6 100644 --- a/modules/isnanl-nolibm-tests +++ b/modules/isnanl-nolibm-tests @@ -3,16 +3,14 @@ tests/test-isnanl-nolibm.c tests/test-isnanl.h tests/minus-zero.h tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentl.m4 Depends-on: float nan +snan configure.ac: -gl_LONG_DOUBLE_EXPONENT_LOCATION AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) Makefile.am: diff --git a/modules/isnanl-tests b/modules/isnanl-tests index 24ea78471e..2206808160 100644 --- a/modules/isnanl-tests +++ b/modules/isnanl-tests @@ -3,16 +3,14 @@ tests/test-isnanl.c tests/test-isnanl.h tests/minus-zero.h tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentl.m4 Depends-on: float nan +snan configure.ac: -gl_LONG_DOUBLE_EXPONENT_LOCATION AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) Makefile.am: diff --git a/modules/signbit-tests b/modules/signbit-tests index c194881503..c491d7c885 100644 --- a/modules/signbit-tests +++ b/modules/signbit-tests @@ -2,20 +2,14 @@ Files: tests/test-signbit.c tests/minus-zero.h tests/infinity.h -tests/snan.h tests/macros.h -m4/exponentf.m4 -m4/exponentd.m4 -m4/exponentl.m4 Depends-on: float qnan +snan configure.ac: -AC_REQUIRE([gl_FLOAT_EXPONENT_LOCATION]) -AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION]) -AC_REQUIRE([gl_LONG_DOUBLE_EXPONENT_LOCATION]) Makefile.am: TESTS += test-signbit diff --git a/modules/snan b/modules/snan new file mode 100644 index 0000000000..2ccbb111db --- /dev/null +++ b/modules/snan @@ -0,0 +1,29 @@ +Description: +Macros for signalling not-a-number. + +Files: +lib/snan.h +m4/snan.m4 +m4/exponentf.m4 +m4/exponentd.m4 +m4/exponentl.m4 + +Depends-on: +nan + +configure.ac: +gl_SNAN + +Makefile.am: +lib_SOURCES += snan.h + +Include: +"snan.h" + +Link: + +License: +GPL + +Maintainer: +all diff --git a/modules/stdio-tests b/modules/stdio-tests index d1bec9d441..5f94d3961d 100644 --- a/modules/stdio-tests +++ b/modules/stdio-tests @@ -1,12 +1,12 @@ Files: tests/test-stdio.c -tests/snan.h tests/macros.h m4/exponentd.m4 Depends-on: assert-h qnan +snan stdio-c++-tests fgetc-tests fputc-tests diff --git a/tests/snan.h b/tests/snan.h deleted file mode 100644 index e877000ece..0000000000 --- a/tests/snan.h +++ /dev/null @@ -1,120 +0,0 @@ -/* Macros for signalling not-a-number. - Copyright (C) 2007-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 . */ - -#include -#include -#include - -#include "nan.h" - - -#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT - -# define HAVE_SNANF 1 - -/* Returns a signalling 'float' NaN. */ -_GL_UNUSED static float -SNaNf () -{ - #define NWORDS \ - ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) - typedef union { float value; unsigned int word[NWORDS]; } memory_float; - memory_float m; - m.value = NaNf (); - #if FLT_EXPBIT0_BIT > 0 - m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1); - #else - m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] - ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1); - #endif - if (FLT_EXPBIT0_WORD < NWORDS / 2) - m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT; - else - m.word[0] |= (unsigned int) 1; - #undef NWORDS - return m.value; -} - -#endif - - -#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT - -# define HAVE_SNAND 1 - -/* Returns a signalling 'double' NaN. */ -_GL_UNUSED static double -SNaNd () -{ - #define NWORDS \ - ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) - typedef union { double value; unsigned int word[NWORDS]; } memory_double; - memory_double m; - m.value = NaNd (); - #if DBL_EXPBIT0_BIT > 0 - m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1); - #else - m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] - ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1); - #endif - m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] - |= (unsigned int) 1 << DBL_EXPBIT0_BIT; - #undef NWORDS - return m.value; -} - -#endif - - -#if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT - -# define HAVE_SNANL 1 - -/* Returns a signalling 'long double' NaN. */ -_GL_UNUSED static long double -SNaNl () -{ - /* A bit pattern that is different from a Quiet NaN. With a bit of luck, - it's a Signalling NaN. */ - #define NWORDS \ - ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) - typedef union { unsigned int word[NWORDS]; long double value; } - memory_long_double; - memory_long_double m; - m.value = NaNl (); - #if defined __powerpc__ && LDBL_MANT_DIG == 106 - /* This is PowerPC "double double", a pair of two doubles. Inf and NaN are - represented as the corresponding 64-bit IEEE values in the first double; - the second is ignored. Manipulate only the first double. */ - #define HNWORDS \ - ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) - #else - #define HNWORDS NWORDS - #endif - #if LDBL_EXPBIT0_BIT > 0 - m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1); - #else - m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < HNWORDS / 2 ? 1 : - 1)] - ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1); - #endif - m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < HNWORDS / 2 ? 1 : - 1)] - |= (unsigned int) 1 << LDBL_EXPBIT0_BIT; - #undef HNWORDS - #undef NWORDS - return m.value; -} - -#endif