Debian Codegraph @

lib/float.in.h

raw
1 /* A correct <float.h>.
2
3 Copyright (C) 2007-2026 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 8.3, the values of LDBL_MAX and LDBL_EPSILON are
119 wrong.
120 Assume these bugs are fixed in any GCC new enough
121 to define __LDBL_NORM_MAX__. */
122 #if (defined _ARCH_PPC && LDBL_MANT_DIG == 106 \
123 && defined __GNUC__ && !defined __LDBL_NORM_MAX__)
124 # undef LDBL_MIN_EXP
125 # define LDBL_MIN_EXP (-968)
126 # undef LDBL_MIN_10_EXP
127 # define LDBL_MIN_10_EXP (-291)
128 # undef LDBL_MIN
129 # define LDBL_MIN 0x1p-969L
130
131 /* IBM long double is tricky: it is represented as the sum of two doubles,
132 and the high double must equal the sum of the two parts rounded to nearest.
133 The maximum finite value for which this is true is
134 { 0x1.fffffffffffffp+1023, 0x1.ffffffffffffep+969 },
135 which represents 0x1.fffffffffffff7ffffffffffff8p+1023L.
136 Although computations can yield representations of numbers larger than this,
137 these computations are considered to have overflowed and behavior is undefined.
138 See <https://gcc.gnu.org/PR120993>. */
139 # undef LDBL_MAX
140 # define LDBL_MAX 0x1.fffffffffffff7ffffffffffff8p+1023L
141
142 /* On PowerPC platforms, 'long double' has a double-double representation.
143 Up to ISO C 17, this was outside the scope of ISO C because it can represent
144 numbers with mantissas of the form 1.<52 bits><many zeroes><52 bits>, such as
145 1.0L + 4.94065645841246544176568792868221e-324L = 1 + 2^-1074; see
146 ISO C 17 § 5.2.4.2.2.(3).
147 In ISO C 23, wording has been included that makes this 'long double'
148 representation compliant; see ISO C 23 § 5.2.5.3.3.(8)-(9). In this setting,
149 numbers with mantissas of the form 1.<52 bits><many zeroes><52 bits> are
150 called "unnormalized". And since LDBL_EPSILON must be normalized (per
151 ISO C 23 § 5.2.5.3.3.(33)), it must be 2^-105. */
152 # undef LDBL_EPSILON
153 # define LDBL_EPSILON 0x1p-105L
154 #endif
155
156 /* ============================ ISO C11 support ============================ */
157
158 /* 'float' properties */
159
160 #ifndef FLT_HAS_SUBNORM
161 # define FLT_HAS_SUBNORM 1
162 #endif
163 #ifndef FLT_DECIMAL_DIG
164 /* FLT_MANT_DIG = 24 => FLT_DECIMAL_DIG = 9 */
165 # define FLT_DECIMAL_DIG ((int)(FLT_MANT_DIG * 0.3010299956639812 + 2))
166 #endif
167 #if defined _AIX && !defined __GNUC__
168 /* On AIX, the value of FLT_TRUE_MIN in /usr/include/float.h is a 'double',
169 not a 'float'. */
170 # undef FLT_TRUE_MIN
171 #endif
172 #ifndef FLT_TRUE_MIN
173 /* FLT_MIN / 2^(FLT_MANT_DIG-1) */
174 # define FLT_TRUE_MIN (FLT_MIN / 8388608.0f)
175 #endif
176
177 /* 'double' properties */
178
179 #ifndef DBL_HAS_SUBNORM
180 # define DBL_HAS_SUBNORM 1
181 #endif
182 #ifndef DBL_DECIMAL_DIG
183 /* DBL_MANT_DIG = 53 => DBL_DECIMAL_DIG = 17 */
184 # define DBL_DECIMAL_DIG ((int)(DBL_MANT_DIG * 0.3010299956639812 + 2))
185 #endif
186 #ifndef DBL_TRUE_MIN
187 /* DBL_MIN / 2^(DBL_MANT_DIG-1) */
188 # define DBL_TRUE_MIN (DBL_MIN / 4503599627370496.0)
189 #endif
190
191 /* 'long double' properties */
192
193 #ifndef LDBL_HAS_SUBNORM
194 # define LDBL_HAS_SUBNORM 1
195 #endif
196 #ifndef LDBL_DECIMAL_DIG
197 /* LDBL_MANT_DIG = 53 => LDBL_DECIMAL_DIG = 17 */
198 /* LDBL_MANT_DIG = 64 => LDBL_DECIMAL_DIG = 21 */
199 /* LDBL_MANT_DIG = 106 => LDBL_DECIMAL_DIG = 33 */
200 /* LDBL_MANT_DIG = 113 => LDBL_DECIMAL_DIG = 36 */
201 # define LDBL_DECIMAL_DIG ((int)(LDBL_MANT_DIG * 0.3010299956639812 + 2))
202 #endif
203 #ifndef LDBL_TRUE_MIN
204 /* LDBL_MIN / 2^(LDBL_MANT_DIG-1) */
205 # if LDBL_MANT_DIG == 53
206 # define LDBL_TRUE_MIN (LDBL_MIN / 4503599627370496.0L)
207 # elif LDBL_MANT_DIG == 64
208 # if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
209 /* Work around FreeBSD/x86 problem mentioned above. */
210 extern const union gl_long_double_union gl_LDBL_TRUE_MIN;
211 # define LDBL_TRUE_MIN (gl_LDBL_TRUE_MIN.ld)
212 # else
213 # define LDBL_TRUE_MIN (LDBL_MIN / 9223372036854775808.0L)
214 # endif
215 # elif LDBL_MANT_DIG == 106
216 # define LDBL_TRUE_MIN (LDBL_MIN / 40564819207303340847894502572032.0L)
217 # elif LDBL_MANT_DIG == 113
218 # define LDBL_TRUE_MIN (LDBL_MIN / 5192296858534827628530496329220096.0L)
219 # endif
220 #endif
221
222 /* ============================ ISO C23 support ============================ */
223
224 /* 'float' properties */
225
226 #ifndef FLT_IS_IEC_60559
227 # if defined __m68k__
228 # define FLT_IS_IEC_60559 0
229 # else
230 # define FLT_IS_IEC_60559 1
231 # endif
232 #endif
233 #ifndef FLT_NORM_MAX
234 # define FLT_NORM_MAX FLT_MAX
235 #endif
236 #ifndef FLT_SNAN
237 /* For sh, beware of <https://gcc.gnu.org/PR111814>. */
238 # if ((__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__) && !defined __sh__
239 # define FLT_SNAN __builtin_nansf ("")
240 # else
241 typedef union { unsigned int word[1]; float value; } gl_FLT_SNAN_t;
242 extern gl_FLT_SNAN_t gl_FLT_SNAN;
243 # define FLT_SNAN (gl_FLT_SNAN.value)
244 # define GNULIB_defined_FLT_SNAN 1
245 # endif
246 #endif
247
248 /* 'double' properties */
249
250 #ifndef DBL_IS_IEC_60559
251 # if defined __m68k__
252 # define DBL_IS_IEC_60559 0
253 # else
254 # define DBL_IS_IEC_60559 1
255 # endif
256 #endif
257 #ifndef DBL_NORM_MAX
258 # define DBL_NORM_MAX DBL_MAX
259 #endif
260 #ifndef DBL_SNAN
261 /* For sh, beware of <https://gcc.gnu.org/PR111814>. */
262 # if ((__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__) && !defined __sh__
263 # define DBL_SNAN __builtin_nans ("")
264 # else
265 typedef union { unsigned long long word[1]; double value; } gl_DBL_SNAN_t;
266 extern gl_DBL_SNAN_t gl_DBL_SNAN;
267 # define DBL_SNAN (gl_DBL_SNAN.value)
268 # define GNULIB_defined_DBL_SNAN 1
269 # endif
270 #endif
271
272 /* 'long double' properties */
273
274 #ifndef LDBL_IS_IEC_60559
275 # if defined __m68k__
276 # define LDBL_IS_IEC_60559 0
277 # elif LDBL_MANT_DIG == 53 || LDBL_MANT_DIG == 113
278 # define LDBL_IS_IEC_60559 1
279 # else
280 # define LDBL_IS_IEC_60559 0
281 # endif
282 #endif
283 #ifndef LDBL_NORM_MAX
284 # ifdef __LDBL_NORM_MAX__
285 # define LDBL_NORM_MAX __LDBL_NORM_MAX__
286 # elif FLT_RADIX == 2 && LDBL_MAX_EXP == 1024 && LDBL_MANT_DIG == 106
287 # define LDBL_NORM_MAX 0x1.ffffffffffffffffffffffffff8p+1022L
288 # else
289 # define LDBL_NORM_MAX LDBL_MAX
290 # endif
291 #endif
292 #ifndef LDBL_SNAN
293 /* For sh, beware of <https://gcc.gnu.org/PR111814>. */
294 # if ((__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__) && !defined __sh__
295 # define LDBL_SNAN __builtin_nansl ("")
296 # else
297 # if LDBL_MANT_DIG == 53
298 typedef union { unsigned long long word[1]; long double value; } gl_LDBL_SNAN_t;
299 # elif defined __m68k__
300 typedef union { unsigned int word[3]; long double value; } gl_LDBL_SNAN_t;
301 # else
302 typedef union { unsigned long long word[2]; long double value; } gl_LDBL_SNAN_t;
303 # endif
304 extern gl_LDBL_SNAN_t gl_LDBL_SNAN;
305 # define LDBL_SNAN (gl_LDBL_SNAN.value)
306 # define GNULIB_defined_LDBL_SNAN 1
307 # endif
308 #endif
309
310 /* ================================= Other ================================= */
311
312 #if @REPLACE_ITOLD@
313 /* Pull in a function that fixes the 'int' to 'long double' conversion
314 of glibc 2.7. */
315 extern
316 # ifdef __cplusplus
317 "C"
318 # endif
319 void _Qp_itoq (long double *, int);
320 static void (*_gl_float_fix_itold) (long double *, int) = _Qp_itoq;
321 #endif
322
323 #endif /* _@GUARD_PREFIX@_FLOAT_H */
324 #endif /* _@GUARD_PREFIX@_FLOAT_H */