exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / nan.h
blobd540a0bb84301438a5ee81ed632f24fd1b5e002d
1 /* Macros for quiet not-a-number.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #ifndef _GL_NAN_H
18 #define _GL_NAN_H
21 /* IBM z/OS supports both hexadecimal and IEEE floating-point formats. The
22 former does not support NaN and its isnan() implementation returns zero
23 for all values. */
24 #if defined __MVS__ && defined __IBMC__ && !defined __BFP__
25 # error "NaN is not supported with IBM's hexadecimal floating-point format; please re-compile with -qfloat=ieee"
26 #endif
28 /* NaNf () returns a 'float' not-a-number. */
30 /* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler choke
31 on the expression 0.0 / 0.0. The IBM XL C compiler on z/OS complains.
32 PGI 16.10 complains. clang 13 on mips64 does incorrect constant-folding. */
33 #if (defined __DECC || defined _MSC_VER \
34 || (defined __MVS__ && defined __IBMC__) \
35 || defined __PGI \
36 || defined __mips__)
37 static float
38 NaNf ()
40 static float volatile zero = 0.0f;
41 return zero / zero;
43 #else
44 # define NaNf() (0.0f / 0.0f)
45 #endif
48 /* NaNd () returns a 'double' not-a-number. */
50 /* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler choke
51 on the expression 0.0 / 0.0. The IBM XL C compiler on z/OS complains.
52 PGI 16.10 complains. clang 13 on mips64 does incorrect constant-folding. */
53 #if (defined __DECC || defined _MSC_VER \
54 || (defined __MVS__ && defined __IBMC__) \
55 || defined __PGI \
56 || defined __mips__)
57 static double
58 NaNd ()
60 static double volatile zero = 0.0;
61 return zero / zero;
63 #else
64 # define NaNd() (0.0 / 0.0)
65 #endif
68 /* NaNl () returns a 'long double' not-a-number. */
70 /* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
71 runtime type conversion.
72 The Microsoft MSVC 9 compiler chokes on the expression 0.0L / 0.0L.
73 The IBM XL C compiler on z/OS complains.
74 PGI 16.10 complains.
75 Avoid possible incorrect constant-folding on mips. */
76 #ifdef __sgi
77 static long double NaNl ()
79 double zero = 0.0;
80 return zero / zero;
82 #elif (defined _MSC_VER \
83 || (defined __MVS__ && defined __IBMC__) \
84 || defined __PGI \
85 || defined __mips__)
86 static long double
87 NaNl ()
89 static long double volatile zero = 0.0L;
90 return zero / zero;
92 #else
93 # define NaNl() (0.0L / 0.0L)
94 #endif
97 #endif /* _GL_NAN_H */