| 1 | /* A correct <float.h>.
|
|---|
| 2 |
|
|---|
| 3 | Copyright (C) 2007-2021 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 | /* 'long double' properties. */
|
|---|
| 32 |
|
|---|
| 33 | #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
|
|---|
| 34 | /* Number of mantissa units, in base FLT_RADIX. */
|
|---|
| 35 | # undef LDBL_MANT_DIG
|
|---|
| 36 | # define LDBL_MANT_DIG 64
|
|---|
| 37 | /* Number of decimal digits that is sufficient for representing a number. */
|
|---|
| 38 | # undef LDBL_DIG
|
|---|
| 39 | # define LDBL_DIG 18
|
|---|
| 40 | /* x-1 where x is the smallest representable number > 1. */
|
|---|
| 41 | # undef LDBL_EPSILON
|
|---|
| 42 | # define LDBL_EPSILON 1.0842021724855044340E-19L
|
|---|
| 43 | /* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
|
|---|
| 44 | # undef LDBL_MIN_EXP
|
|---|
| 45 | # define LDBL_MIN_EXP (-16381)
|
|---|
| 46 | /* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
|
|---|
| 47 | # undef LDBL_MAX_EXP
|
|---|
| 48 | # define LDBL_MAX_EXP 16384
|
|---|
| 49 | /* Minimum positive normalized number. */
|
|---|
| 50 | # undef LDBL_MIN
|
|---|
| 51 | # define LDBL_MIN 3.3621031431120935063E-4932L
|
|---|
| 52 | /* Maximum representable finite number. */
|
|---|
| 53 | # undef LDBL_MAX
|
|---|
| 54 | # define LDBL_MAX 1.1897314953572317650E+4932L
|
|---|
| 55 | /* Minimum e such that 10^e is in the range of normalized numbers. */
|
|---|
| 56 | # undef LDBL_MIN_10_EXP
|
|---|
| 57 | # define LDBL_MIN_10_EXP (-4931)
|
|---|
| 58 | /* Maximum e such that 10^e is in the range of representable finite numbers. */
|
|---|
| 59 | # undef LDBL_MAX_10_EXP
|
|---|
| 60 | # define LDBL_MAX_10_EXP 4932
|
|---|
| 61 | #endif
|
|---|
| 62 |
|
|---|
| 63 | /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
|
|---|
| 64 | precision in the compiler but 64 bits of precision at runtime. See
|
|---|
| 65 | <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>. */
|
|---|
| 66 | #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
|
|---|
| 67 | /* Number of mantissa units, in base FLT_RADIX. */
|
|---|
| 68 | # undef LDBL_MANT_DIG
|
|---|
| 69 | # define LDBL_MANT_DIG 64
|
|---|
| 70 | /* Number of decimal digits that is sufficient for representing a number. */
|
|---|
| 71 | # undef LDBL_DIG
|
|---|
| 72 | # define LDBL_DIG 18
|
|---|
| 73 | /* x-1 where x is the smallest representable number > 1. */
|
|---|
| 74 | # undef LDBL_EPSILON
|
|---|
| 75 | # define LDBL_EPSILON 1.084202172485504434007452800869941711426e-19L /* 2^-63 */
|
|---|
| 76 | /* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
|
|---|
| 77 | # undef LDBL_MIN_EXP
|
|---|
| 78 | # define LDBL_MIN_EXP (-16381)
|
|---|
| 79 | /* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
|
|---|
| 80 | # undef LDBL_MAX_EXP
|
|---|
| 81 | # define LDBL_MAX_EXP 16384
|
|---|
| 82 | /* Minimum positive normalized number. */
|
|---|
| 83 | # undef LDBL_MIN
|
|---|
| 84 | # define LDBL_MIN 3.362103143112093506262677817321752E-4932L /* = 0x1p-16382L */
|
|---|
| 85 | /* Maximum representable finite number. */
|
|---|
| 86 | # undef LDBL_MAX
|
|---|
| 87 | /* LDBL_MAX is represented as { 0xFFFFFFFF, 0xFFFFFFFF, 32766 }.
|
|---|
| 88 | But the largest literal that GCC allows us to write is
|
|---|
| 89 | 0x0.fffffffffffff8p16384L = { 0xFFFFF800, 0xFFFFFFFF, 32766 }.
|
|---|
| 90 | So, define it like this through a reference to an external variable
|
|---|
| 91 |
|
|---|
| 92 | const unsigned int LDBL_MAX[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 32766 };
|
|---|
| 93 | extern const long double LDBL_MAX;
|
|---|
| 94 |
|
|---|
| 95 | Unfortunately, this is not a constant expression. */
|
|---|
| 96 | # if !GNULIB_defined_long_double_union
|
|---|
| 97 | union gl_long_double_union
|
|---|
| 98 | {
|
|---|
| 99 | struct { unsigned int lo; unsigned int hi; unsigned int exponent; } xd;
|
|---|
| 100 | long double ld;
|
|---|
| 101 | };
|
|---|
| 102 | # define GNULIB_defined_long_double_union 1
|
|---|
| 103 | # endif
|
|---|
| 104 | extern const union gl_long_double_union gl_LDBL_MAX;
|
|---|
| 105 | # define LDBL_MAX (gl_LDBL_MAX.ld)
|
|---|
| 106 | /* Minimum e such that 10^e is in the range of normalized numbers. */
|
|---|
| 107 | # undef LDBL_MIN_10_EXP
|
|---|
| 108 | # define LDBL_MIN_10_EXP (-4931)
|
|---|
| 109 | /* Maximum e such that 10^e is in the range of representable finite numbers. */
|
|---|
| 110 | # undef LDBL_MAX_10_EXP
|
|---|
| 111 | # define LDBL_MAX_10_EXP 4932
|
|---|
| 112 | #endif
|
|---|
| 113 |
|
|---|
| 114 | /* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are
|
|---|
| 115 | wrong.
|
|---|
| 116 | On Linux/PowerPC with gcc 4.4, the value of LDBL_MAX is wrong. */
|
|---|
| 117 | #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
|
|---|
| 118 | # undef LDBL_MIN_EXP
|
|---|
| 119 | # define LDBL_MIN_EXP DBL_MIN_EXP
|
|---|
| 120 | # undef LDBL_MIN_10_EXP
|
|---|
| 121 | # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
|
|---|
| 122 | # undef LDBL_MIN
|
|---|
| 123 | # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
|
|---|
| 124 | #endif
|
|---|
| 125 | #if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
|
|---|
| 126 | # undef LDBL_MAX
|
|---|
| 127 | /* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF }.
|
|---|
| 128 | It is not easy to define:
|
|---|
| 129 | #define LDBL_MAX 1.79769313486231580793728971405302307166e308L
|
|---|
| 130 | is too small, whereas
|
|---|
| 131 | #define LDBL_MAX 1.79769313486231580793728971405302307167e308L
|
|---|
| 132 | is too large. Apparently a bug in GCC decimal-to-binary conversion.
|
|---|
| 133 | Also, I can't get values larger than
|
|---|
| 134 | #define LDBL63 ((long double) (1ULL << 63))
|
|---|
| 135 | #define LDBL882 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
|
|---|
| 136 | #define LDBL945 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
|
|---|
| 137 | #define LDBL1008 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
|
|---|
| 138 | #define LDBL_MAX (LDBL1008 * 65535.0L + LDBL945 * (long double) 9223372036821221375ULL + LDBL882 * (long double) 4611686018427387904ULL)
|
|---|
| 139 | which is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xF8000000 }.
|
|---|
| 140 | So, define it like this through a reference to an external variable
|
|---|
| 141 |
|
|---|
| 142 | const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL };
|
|---|
| 143 | extern const long double LDBL_MAX;
|
|---|
| 144 |
|
|---|
| 145 | or through a pointer cast
|
|---|
| 146 |
|
|---|
| 147 | #define LDBL_MAX \
|
|---|
| 148 | (*(const long double *) (double[]) { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL })
|
|---|
| 149 |
|
|---|
| 150 | Unfortunately, this is not a constant expression, and the latter expression
|
|---|
| 151 | does not work well when GCC is optimizing.. */
|
|---|
| 152 | # if !GNULIB_defined_long_double_union
|
|---|
| 153 | union gl_long_double_union
|
|---|
| 154 | {
|
|---|
| 155 | struct { double hi; double lo; } dd;
|
|---|
| 156 | long double ld;
|
|---|
| 157 | };
|
|---|
| 158 | # define GNULIB_defined_long_double_union 1
|
|---|
| 159 | # endif
|
|---|
| 160 | extern const union gl_long_double_union gl_LDBL_MAX;
|
|---|
| 161 | # define LDBL_MAX (gl_LDBL_MAX.ld)
|
|---|
| 162 | #endif
|
|---|
| 163 |
|
|---|
| 164 | /* On IRIX 6.5, with cc, the value of LDBL_MANT_DIG is wrong.
|
|---|
| 165 | On IRIX 6.5, with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_EPSILON
|
|---|
| 166 | are wrong. */
|
|---|
| 167 | #if defined __sgi && (LDBL_MANT_DIG >= 106)
|
|---|
| 168 | # undef LDBL_MANT_DIG
|
|---|
| 169 | # define LDBL_MANT_DIG 106
|
|---|
| 170 | # if defined __GNUC__
|
|---|
| 171 | # undef LDBL_MIN_EXP
|
|---|
| 172 | # define LDBL_MIN_EXP DBL_MIN_EXP
|
|---|
| 173 | # undef LDBL_MIN_10_EXP
|
|---|
| 174 | # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
|
|---|
| 175 | # undef LDBL_MIN
|
|---|
| 176 | # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
|
|---|
| 177 | # undef LDBL_EPSILON
|
|---|
| 178 | # define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 */
|
|---|
| 179 | # endif
|
|---|
| 180 | #endif
|
|---|
| 181 |
|
|---|
| 182 | #if @REPLACE_ITOLD@
|
|---|
| 183 | /* Pull in a function that fixes the 'int' to 'long double' conversion
|
|---|
| 184 | of glibc 2.7. */
|
|---|
| 185 | extern
|
|---|
| 186 | # ifdef __cplusplus
|
|---|
| 187 | "C"
|
|---|
| 188 | # endif
|
|---|
| 189 | void _Qp_itoq (long double *, int);
|
|---|
| 190 | static void (*_gl_float_fix_itold) (long double *, int) = _Qp_itoq;
|
|---|
| 191 | #endif
|
|---|
| 192 |
|
|---|
| 193 | #endif /* _@GUARD_PREFIX@_FLOAT_H */
|
|---|
| 194 | #endif /* _@GUARD_PREFIX@_FLOAT_H */
|
|---|