From: Bruno Haible Date: Thu, 12 Oct 2023 19:12:53 +0000 (+0200) Subject: qnan: New module. X-Git-Tag: v1.0~722 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a5dbfe68ecfd8fe7710139b1a87af811de97c0cb;p=gnulib.git qnan: New module. * lib/qnan.h: Renamed from tests/qnan.h. Add double-inclusion guard. * modules/qnan: New file. * modules/signbit-tests (Files): Remove tests/qnan.h. (Depends-on): Add qnan. Remove nan. * modules/stdio-tests (Files): Remove tests/qnan.h. (Depends-on): Add qnan. Remove nan. * modules/totalorder-tests (Files): Remove tests/qnan.h. (Depends-on): Add qnan. Remove nan, signbit. * modules/totalorderf-tests (Files): Remove tests/qnan.h. (Depends-on): Add qnan. Remove nan, signbit. * modules/totalorderl-tests (Files): Remove tests/qnan.h. (Depends-on): Add qnan. Remove nan, signbit. --- diff --git a/ChangeLog b/ChangeLog index 9014954a2f..b072697e2a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2023-10-12 Bruno Haible + + qnan: New module. + * lib/qnan.h: Renamed from tests/qnan.h. Add double-inclusion guard. + * modules/qnan: New file. + * modules/signbit-tests (Files): Remove tests/qnan.h. + (Depends-on): Add qnan. Remove nan. + * modules/stdio-tests (Files): Remove tests/qnan.h. + (Depends-on): Add qnan. Remove nan. + * modules/totalorder-tests (Files): Remove tests/qnan.h. + (Depends-on): Add qnan. Remove nan, signbit. + * modules/totalorderf-tests (Files): Remove tests/qnan.h. + (Depends-on): Add qnan. Remove nan, signbit. + * modules/totalorderl-tests (Files): Remove tests/qnan.h. + (Depends-on): Add qnan. Remove nan, signbit. + 2023-10-12 Bruno Haible nan: New module. diff --git a/lib/qnan.h b/lib/qnan.h new file mode 100644 index 0000000000..e6538c227e --- /dev/null +++ b/lib/qnan.h @@ -0,0 +1,88 @@ +/* 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 . */ + +#ifndef _QNAN_H +#define _QNAN_H + +#include + +#include "nan.h" + + +/* Returns a quiet 'float' NaN with sign bit == 0. */ +_GL_UNUSED static float +positive_NaNf () +{ + /* 'volatile' works around a GCC bug: + */ + 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: + */ + 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: + */ + 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: + */ + 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: + */ + 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: + */ + long double volatile nan = NaNl (); + return (signbit (nan) ? nan : - nan); +} + + +#endif /* _QNAN_H */ diff --git a/modules/qnan b/modules/qnan new file mode 100644 index 0000000000..fd3cbb5097 --- /dev/null +++ b/modules/qnan @@ -0,0 +1,25 @@ +Description: +Macros for quiet not-a-number. + +Files: +lib/qnan.h + +Depends-on: +nan +signbit + +configure.ac: + +Makefile.am: +lib_SOURCES += qnan.h + +Include: +"qnan.h" + +Link: + +License: +GPL + +Maintainer: +all diff --git a/modules/signbit-tests b/modules/signbit-tests index 6e414ea4f2..c194881503 100644 --- a/modules/signbit-tests +++ b/modules/signbit-tests @@ -2,7 +2,6 @@ Files: tests/test-signbit.c tests/minus-zero.h tests/infinity.h -tests/qnan.h tests/snan.h tests/macros.h m4/exponentf.m4 @@ -11,7 +10,7 @@ m4/exponentl.m4 Depends-on: float -nan +qnan configure.ac: AC_REQUIRE([gl_FLOAT_EXPONENT_LOCATION]) diff --git a/modules/stdio-tests b/modules/stdio-tests index f0dc1d054f..d1bec9d441 100644 --- a/modules/stdio-tests +++ b/modules/stdio-tests @@ -1,13 +1,12 @@ Files: tests/test-stdio.c -tests/qnan.h tests/snan.h tests/macros.h m4/exponentd.m4 Depends-on: assert-h -nan +qnan stdio-c++-tests fgetc-tests fputc-tests diff --git a/modules/totalorder-tests b/modules/totalorder-tests index 6bddc21593..5ff4c752f0 100644 --- a/modules/totalorder-tests +++ b/modules/totalorder-tests @@ -2,12 +2,10 @@ Files: tests/test-totalorder.c tests/minus-zero.h tests/infinity.h -tests/qnan.h tests/macros.h Depends-on: -nan -signbit +qnan configure.ac: diff --git a/modules/totalorderf-tests b/modules/totalorderf-tests index 688536be81..7e2e7938f6 100644 --- a/modules/totalorderf-tests +++ b/modules/totalorderf-tests @@ -3,12 +3,10 @@ tests/test-totalorderf.c tests/test-totalorder.c tests/minus-zero.h tests/infinity.h -tests/qnan.h tests/macros.h Depends-on: -nan -signbit +qnan configure.ac: diff --git a/modules/totalorderl-tests b/modules/totalorderl-tests index 1502a9d5ce..1b6ca5200f 100644 --- a/modules/totalorderl-tests +++ b/modules/totalorderl-tests @@ -3,12 +3,10 @@ tests/test-totalorderl.c tests/test-totalorder.c tests/minus-zero.h tests/infinity.h -tests/qnan.h tests/macros.h Depends-on: -nan -signbit +qnan configure.ac: diff --git a/tests/qnan.h b/tests/qnan.h deleted file mode 100644 index 7006699865..0000000000 --- a/tests/qnan.h +++ /dev/null @@ -1,82 +0,0 @@ -/* 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 . */ - -#include - -#include "nan.h" - - -/* Returns a quiet 'float' NaN with sign bit == 0. */ -_GL_UNUSED static float -positive_NaNf () -{ - /* 'volatile' works around a GCC bug: - */ - 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: - */ - 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: - */ - 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: - */ - 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: - */ - 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: - */ - long double volatile nan = NaNl (); - return (signbit (nan) ? nan : - nan); -}