| 1 |
/* Macros for quiet not-a-number. |
| 2 |
Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is free software: you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU Lesser General Public License as |
| 6 |
published by the Free Software Foundation; either version 2.1 of the |
| 7 |
License, or (at your option) any later version. |
| 8 |
|
| 9 |
This file 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 Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 16 |
|
| 17 |
#ifndef _GL_NAN_H |
| 18 |
#define _GL_NAN_H |
| 19 |
|
| 20 |
/* IBM z/OS supports both hexadecimal and IEEE floating-point formats. The |
| 21 |
former does not support NaN and its isnan() implementation returns zero |
| 22 |
for all values. */ |
| 23 |
#if defined __MVS__ && defined __IBMC__ && !defined __BFP__ |
| 24 |
# error "NaN is not supported with IBM's hexadecimal floating-point format; please re-compile with -qfloat=ieee" |
| 25 |
#endif |
| 26 |
|
| 27 |
#ifdef __cplusplus |
| 28 |
extern "C" { |
| 29 |
#endif |
| 30 |
|
| 31 |
|
| 32 |
/* NaNf () returns a 'float' not-a-number. */ |
| 33 |
|
| 34 |
/* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler choke |
| 35 |
on the expression 0.0 / 0.0. The IBM XL C compiler on z/OS complains. |
| 36 |
PGI 16.10 complains. clang 13 on mips64 does incorrect constant-folding. */ |
| 37 |
#if (defined __DECC || defined _MSC_VER \ |
| 38 |
|| (defined __MVS__ && defined __IBMC__) \ |
| 39 |
|| defined __PGI \ |
| 40 |
|| defined __mips__) |
| 41 |
static float |
| 42 |
NaNf () |
| 43 |
{ |
| 44 |
static float volatile zero = 0.0f; |
| 45 |
return zero / zero; |
| 46 |
} |
| 47 |
#else |
| 48 |
# define NaNf() (0.0f / 0.0f) |
| 49 |
#endif |
| 50 |
|
| 51 |
|
| 52 |
/* NaNd () returns a 'double' not-a-number. */ |
| 53 |
|
| 54 |
/* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler choke |
| 55 |
on the expression 0.0 / 0.0. The IBM XL C compiler on z/OS complains. |
| 56 |
PGI 16.10 complains. clang 13 on mips64 does incorrect constant-folding. */ |
| 57 |
#if (defined __DECC || defined _MSC_VER \ |
| 58 |
|| (defined __MVS__ && defined __IBMC__) \ |
| 59 |
|| defined __PGI \ |
| 60 |
|| defined __mips__) |
| 61 |
static double |
| 62 |
NaNd () |
| 63 |
{ |
| 64 |
static double volatile zero = 0.0; |
| 65 |
return zero / zero; |
| 66 |
} |
| 67 |
#else |
| 68 |
# define NaNd() (0.0 / 0.0) |
| 69 |
#endif |
| 70 |
|
| 71 |
|
| 72 |
/* NaNl () returns a 'long double' not-a-number. */ |
| 73 |
|
| 74 |
/* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the |
| 75 |
runtime type conversion. |
| 76 |
The Microsoft MSVC 9 compiler chokes on the expression 0.0L / 0.0L. |
| 77 |
The IBM XL C compiler on z/OS complains. |
| 78 |
PGI 16.10 complains. |
| 79 |
Avoid possible incorrect constant-folding on mips. */ |
| 80 |
#ifdef __sgi |
| 81 |
static long double NaNl () |
| 82 |
{ |
| 83 |
double zero = 0.0; |
| 84 |
return zero / zero; |
| 85 |
} |
| 86 |
#elif (defined _MSC_VER \ |
| 87 |
|| (defined __MVS__ && defined __IBMC__) \ |
| 88 |
|| defined __PGI \ |
| 89 |
|| defined __mips__) |
| 90 |
static long double |
| 91 |
NaNl () |
| 92 |
{ |
| 93 |
static long double volatile zero = 0.0L; |
| 94 |
return zero / zero; |
| 95 |
} |
| 96 |
#else |
| 97 |
# define NaNl() (0.0L / 0.0L) |
| 98 |
#endif |
| 99 |
|
| 100 |
|
| 101 |
#ifdef __cplusplus |
| 102 |
} |
| 103 |
#endif |
| 104 |
|
| 105 |
#endif /* _GL_NAN_H */ |