Debian Codegraph @

lib/float.in.h

raw
1 /* A correct <float.h>.
2
3 Copyright (C) 2007-2024 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18 #ifndef _@GUARD_PREFIX@_FLOAT_H
19
20 #if __GNUC__ >= 3
21 @PRAGMA_SYSTEM_HEADER@
22 #endif
23 @PRAGMA_COLUMNS@
24
25 /* The include_next requires a split double-inclusion guard. */
26 #@INCLUDE_NEXT@ @NEXT_FLOAT_H@
27
28 #ifndef _@GUARD_PREFIX@_FLOAT_H
29 #define _@GUARD_PREFIX@_FLOAT_H
30
31 /* ============================ ISO C99 support ============================ */
32
33 /* 'long double' properties. */
34
35 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
36 /* Number of mantissa units, in base FLT_RADIX. */
37 # undef LDBL_MANT_DIG
38 # define LDBL_MANT_DIG 64
39 /* Number of decimal digits that is sufficient for representing a number. */
40 # undef LDBL_DIG
41 # define LDBL_DIG 18
42 /* x-1 where x is the smallest representable number > 1. */
43 # undef LDBL_EPSILON
44 # define LDBL_EPSILON 1.0842021724855044340E-19L
45 /* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
46 # undef LDBL_MIN_EXP
47 # define LDBL_MIN_EXP (-16381)
48 /* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
49 # undef LDBL_MAX_EXP
50 # define LDBL_MAX_EXP 16384
51 /* Minimum positive normalized number. */
52 # undef LDBL_MIN
53 # define LDBL_MIN 3.3621031431120935063E-4932L
54 /* Maximum representable finite number. */
55 # undef LDBL_MAX
56 # define LDBL_MAX 1.1897314953572317650E+4932L
57 /* Minimum e such that 10^e is in the range of normalized numbers. */
58 # undef LDBL_MIN_10_EXP
59 # define LDBL_MIN_10_EXP (-4931)
60 /* Maximum e such that 10^e is in the range of representable finite numbers. */
61 # undef LDBL_MAX_10_EXP
62 # define LDBL_MAX_10_EXP 4932
63 #endif
64
65 /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
66 precision in the compiler but 64 bits of precision at runtime. See
67 <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>. */
68 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
69 /* Number of mantissa units, in base FLT_RADIX. */
70 # undef LDBL_MANT_DIG
71 # define LDBL_MANT_DIG 64
72 /* Number of decimal digits that is sufficient for representing a number. */
73 # undef LDBL_DIG
74 # define LDBL_DIG 18
75 /* x-1 where x is the smallest representable number > 1. */
76 # undef LDBL_EPSILON
77 # define LDBL_EPSILON 1.084202172485504434007452800869941711426e-19L /* 2^-63 */
78 /* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
79 # undef LDBL_MIN_EXP
80 # define LDBL_MIN_EXP (-16381)
81 /* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
82 # undef LDBL_MAX_EXP
83 # define LDBL_MAX_EXP 16384
84 /* Minimum positive normalized number. */
85 # undef LDBL_MIN
86 # define LDBL_MIN 3.362103143112093506262677817321752E-4932L /* = 0x1p-16382L */
87 /* Maximum representable finite number. */
88 # undef LDBL_MAX
89 /* LDBL_MAX is represented as { 0xFFFFFFFF, 0xFFFFFFFF, 32766 }.
90 But the largest literal that GCC allows us to write is
91 0x0.fffffffffffff8p16384L = { 0xFFFFF800, 0xFFFFFFFF, 32766 }.
92 So, define it like this through a reference to an external variable
93
94 const unsigned int LDBL_MAX[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 32766 };
95 extern const long double LDBL_MAX;
96
97 Unfortunately, this is not a constant expression. */
98 # if !GNULIB_defined_long_double_union
99 union gl_long_double_union
100 {
101 struct { unsigned int lo; unsigned int hi; unsigned int exponent; } xd;
102 long double ld;
103 };
104 # define GNULIB_defined_long_double_union 1
105 # endif
106 extern const union gl_long_double_union gl_LDBL_MAX;
107 # define LDBL_MAX (gl_LDBL_MAX.ld)
108 /* Minimum e such that 10^e is in the range of normalized numbers. */
109 # undef LDBL_MIN_10_EXP
110 # define LDBL_MIN_10_EXP (-4931)
111 /* Maximum e such that 10^e is in the range of representable finite numbers. */
112 # undef LDBL_MAX_10_EXP
113 # define LDBL_MAX_10_EXP 4932
114 #endif
115
116 /* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are
117 wrong.
118 On Linux/PowerPC with gcc 4.4, the value of LDBL_MAX is wrong. */
119 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
120 # undef LDBL_MIN_EXP
121 # define LDBL_MIN_EXP DBL_MIN_EXP
122 # undef LDBL_MIN_10_EXP
123 # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
124 # undef LDBL_MIN
125 # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
126 #endif
127 #if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
128 # undef LDBL_MAX
129 /* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF }.
130 It is not easy to define:
131 #define LDBL_MAX 1.79769313486231580793728971405302307166e308L
132 is too small, whereas
133 #define LDBL_MAX 1.79769313486231580793728971405302307167e308L
134 is too large. Apparently a bug in GCC decimal-to-binary conversion.
135 Also, I can't get values larger than
136 #define LDBL63 ((long double) (1ULL << 63))
137 #define LDBL882 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
138 #define LDBL945 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
139 #define LDBL1008 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
140 #define LDBL_MAX (LDBL1008 * 65535.0L + LDBL945 * (long double) 9223372036821221375ULL + LDBL882 * (long double) 4611686018427387904ULL)
141 which is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xF8000000 }.
142 So, define it like this through a reference to an external variable
143
144 const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL };
145 extern const long double LDBL_MAX;
146
147 or through a pointer cast
148
149 #define LDBL_MAX \
150 (*(const long double *) (double[]) { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL })
151
152 Unfortunately, this is not a constant expression, and the latter expression
153 does not work well when GCC is optimizing.. */
154 # if !GNULIB_defined_long_double_union
155 union gl_long_double_union
156 {
157 struct { double hi; double lo; } dd;
158 long double ld;
159 };
160 # define GNULIB_defined_long_double_union 1
161 # endif
162 extern const union gl_long_double_union gl_LDBL_MAX;
163 # define LDBL_MAX (gl_LDBL_MAX.ld)
164 #endif
165
166 /* On IRIX 6.5, with cc, the value of LDBL_MANT_DIG is wrong.
167 On IRIX 6.5, with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_EPSILON
168 are wrong. */
169 #if defined __sgi && (LDBL_MANT_DIG >= 106)
170 # undef LDBL_MANT_DIG
171 # define LDBL_MANT_DIG 106
172 # if defined __GNUC__
173 # undef LDBL_MIN_EXP
174 # define LDBL_MIN_EXP DBL_MIN_EXP
175 # undef LDBL_MIN_10_EXP
176 # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
177 # undef LDBL_MIN
178 # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
179 # undef LDBL_EPSILON
180 # define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 */
181 # endif
182 #endif
183
184 /* ============================ ISO C11 support ============================ */
185
186 /* 'float' properties */
187
188 #ifndef FLT_HAS_SUBNORM
189 # define FLT_HAS_SUBNORM 1
190 #endif
191 #ifndef FLT_DECIMAL_DIG
192 /* FLT_MANT_DIG = 24 => FLT_DECIMAL_DIG = 9 */
193 # define FLT_DECIMAL_DIG ((int)(FLT_MANT_DIG * 0.3010299956639812 + 2))
194 #endif
195 #if defined _AIX && !defined __GNUC__
196 /* On AIX, the value of FLT_TRUE_MIN in /usr/include/float.h is a 'double',
197 not a 'float'. */
198 # undef FLT_TRUE_MIN
199 #endif
200 #ifndef FLT_TRUE_MIN
201 /* FLT_MIN / 2^(FLT_MANT_DIG-1) */
202 # define FLT_TRUE_MIN (FLT_MIN / 8388608.0f)
203 #endif
204
205 /* 'double' properties */
206
207 #ifndef DBL_HAS_SUBNORM
208 # define DBL_HAS_SUBNORM 1
209 #endif
210 #ifndef DBL_DECIMAL_DIG
211 /* DBL_MANT_DIG = 53 => DBL_DECIMAL_DIG = 17 */
212 # define DBL_DECIMAL_DIG ((int)(DBL_MANT_DIG * 0.3010299956639812 + 2))
213 #endif
214 #ifndef DBL_TRUE_MIN
215 /* DBL_MIN / 2^(DBL_MANT_DIG-1) */
216 # define DBL_TRUE_MIN (DBL_MIN / 4503599627370496.0)
217 #endif
218
219 /* 'long double' properties */
220
221 #ifndef LDBL_HAS_SUBNORM
222 # define LDBL_HAS_SUBNORM 1
223 #endif
224 #ifndef LDBL_DECIMAL_DIG
225 /* LDBL_MANT_DIG = 53 => LDBL_DECIMAL_DIG = 17 */
226 /* LDBL_MANT_DIG = 64 => LDBL_DECIMAL_DIG = 21 */
227 /* LDBL_MANT_DIG = 106 => LDBL_DECIMAL_DIG = 33 */
228 /* LDBL_MANT_DIG = 113 => LDBL_DECIMAL_DIG = 36 */
229 # define LDBL_DECIMAL_DIG ((int)(LDBL_MANT_DIG * 0.3010299956639812 + 2))
230 #endif
231 #ifndef LDBL_TRUE_MIN
232 /* LDBL_MIN / 2^(LDBL_MANT_DIG-1) */
233 # if LDBL_MANT_DIG == 53
234 # define LDBL_TRUE_MIN (LDBL_MIN / 4503599627370496.0L)
235 # elif LDBL_MANT_DIG == 64
236 # if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
237 /* Work around FreeBSD/x86 problem mentioned above. */
238 extern const union gl_long_double_union gl_LDBL_TRUE_MIN;
239 # define LDBL_TRUE_MIN (gl_LDBL_TRUE_MIN.ld)
240 # else
241 # define LDBL_TRUE_MIN (LDBL_MIN / 9223372036854775808.0L)
242 # endif
243 # elif LDBL_MANT_DIG == 106
244 # define LDBL_TRUE_MIN (LDBL_MIN / 40564819207303340847894502572032.0L)
245 # elif LDBL_MANT_DIG == 113
246 # define LDBL_TRUE_MIN (LDBL_MIN / 5192296858534827628530496329220096.0L)
247 # endif
248 #endif
249
250 /* ============================ ISO C23 support ============================ */
251
252 /* 'float' properties */
253
254 #ifndef FLT_IS_IEC_60559
255 # if defined __m68k__
256 # define FLT_IS_IEC_60559 0
257 # else
258 # define FLT_IS_IEC_60559 1
259 # endif
260 #endif
261 #ifndef FLT_NORM_MAX
262 # define FLT_NORM_MAX FLT_MAX
263 #endif
264 #ifndef FLT_SNAN
265 /* For sh, beware of <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111814>. */
266 # if ((__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__) && !defined __sh__
267 # define FLT_SNAN __builtin_nansf ("")
268 # else
269 typedef union { unsigned int word[1]; float value; } gl_FLT_SNAN_t;
270 extern gl_FLT_SNAN_t gl_FLT_SNAN;
271 # define FLT_SNAN (gl_FLT_SNAN.value)
272 # define GNULIB_defined_FLT_SNAN 1
273 # endif
274 #endif
275
276 /* 'double' properties */
277
278 #ifndef DBL_IS_IEC_60559
279 # if defined __m68k__
280 # define DBL_IS_IEC_60559 0
281 # else
282 # define DBL_IS_IEC_60559 1
283 # endif
284 #endif
285 #ifndef DBL_NORM_MAX
286 # define DBL_NORM_MAX DBL_MAX
287 #endif
288 #ifndef DBL_SNAN
289 /* For sh, beware of <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111814>. */
290 # if ((__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__) && !defined __sh__
291 # define DBL_SNAN __builtin_nans ("")
292 # else
293 typedef union { unsigned long long word[1]; double value; } gl_DBL_SNAN_t;
294 extern gl_DBL_SNAN_t gl_DBL_SNAN;
295 # define DBL_SNAN (gl_DBL_SNAN.value)
296 # define GNULIB_defined_DBL_SNAN 1
297 # endif
298 #endif
299
300 /* 'long double' properties */
301
302 #ifndef LDBL_IS_IEC_60559
303 # if defined __m68k__
304 # define LDBL_IS_IEC_60559 0
305 # elif LDBL_MANT_DIG == 53 || LDBL_MANT_DIG == 113
306 # define LDBL_IS_IEC_60559 1
307 # else
308 # define LDBL_IS_IEC_60559 0
309 # endif
310 #endif
311 #ifndef LDBL_NORM_MAX
312 # define LDBL_NORM_MAX LDBL_MAX
313 #endif
314 #ifndef LDBL_SNAN
315 /* For sh, beware of <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111814>. */
316 # if ((__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__) && !defined __sh__
317 # define LDBL_SNAN __builtin_nansl ("")
318 # else
319 # if LDBL_MANT_DIG == 53
320 typedef union { unsigned long long word[1]; long double value; } gl_LDBL_SNAN_t;
321 # elif defined __m68k__
322 typedef union { unsigned int word[3]; long double value; } gl_LDBL_SNAN_t;
323 # else
324 typedef union { unsigned long long word[2]; long double value; } gl_LDBL_SNAN_t;
325 # endif
326 extern gl_LDBL_SNAN_t gl_LDBL_SNAN;
327 # define LDBL_SNAN (gl_LDBL_SNAN.value)
328 # define GNULIB_defined_LDBL_SNAN 1
329 # endif
330 #endif
331
332 /* ================================= Other ================================= */
333
334 #if @REPLACE_ITOLD@
335 /* Pull in a function that fixes the 'int' to 'long double' conversion
336 of glibc 2.7. */
337 extern
338 # ifdef __cplusplus
339 "C"
340 # endif
341 void _Qp_itoq (long double *, int);
342 static void (*_gl_float_fix_itold) (long double *, int) = _Qp_itoq;
343 #endif
344
345 #endif /* _@GUARD_PREFIX@_FLOAT_H */
346 #endif /* _@GUARD_PREFIX@_FLOAT_H */