1 /* Macros for quiet not-a-number.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
29 /* Returns - x, implemented by inverting the sign bit,
30 so that it works also on 'float' NaN values. */
31 _GL_UNUSED
static float
35 /* The mips instruction neg.s may have no effect on NaNs.
36 Therefore, invert the sign bit using integer operations. */
37 union { unsigned int i
; float value
; } u
;
46 /* Returns a quiet 'float' NaN with sign bit == 0. */
47 _GL_UNUSED
static float
50 /* 'volatile' works around a GCC bug:
51 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
52 float volatile nan
= NaNf ();
53 return (signbit (nan
) ? minus_NaNf (nan
) : nan
);
56 /* Returns a quiet 'float' NaN with sign bit == 1. */
57 _GL_UNUSED
static float
60 /* 'volatile' works around a GCC bug:
61 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
62 float volatile nan
= NaNf ();
63 return (signbit (nan
) ? nan
: minus_NaNf (nan
));
67 /* Returns - x, implemented by inverting the sign bit,
68 so that it works also on 'double' NaN values. */
69 _GL_UNUSED
static double
73 /* The mips instruction neg.d may have no effect on NaNs.
74 Therefore, invert the sign bit using integer operations. */
75 union { unsigned long long i
; double value
; } u
;
84 /* Returns a quiet 'double' NaN with sign bit == 0. */
85 _GL_UNUSED
static double
88 /* 'volatile' works around a GCC bug:
89 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
90 double volatile nan
= NaNd ();
91 return (signbit (nan
) ? minus_NaNd (nan
) : nan
);
94 /* Returns a quiet 'double' NaN with sign bit == 1. */
95 _GL_UNUSED
static double
98 /* 'volatile' works around a GCC bug:
99 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
100 double volatile nan
= NaNd ();
101 return (signbit (nan
) ? nan
: minus_NaNd (nan
));
105 /* Returns - x, implemented by inverting the sign bit,
106 so that it works also on 'long double' NaN values. */
107 _GL_UNUSED
static long double
108 minus_NaNl (long double x
)
113 /* Returns a quiet 'long double' NaN with sign bit == 0. */
114 _GL_UNUSED
static long double
117 /* 'volatile' works around a GCC bug:
118 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
119 long double volatile nan
= NaNl ();
120 return (signbit (nan
) ? minus_NaNl (nan
) : nan
);
123 /* Returns a quiet 'long double' NaN with sign bit == 1. */
124 _GL_UNUSED
static long double
127 /* 'volatile' works around a GCC bug:
128 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
129 long double volatile nan
= NaNl ();
130 return (signbit (nan
) ? nan
: minus_NaNl (nan
));
138 #endif /* _SIGNED_NAN_H */