float.in.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* A correct <float.h>.
  2. Copyright (C) 2007-2021 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. #ifndef _@GUARD_PREFIX@_FLOAT_H
  14. #if __GNUC__ >= 3
  15. @PRAGMA_SYSTEM_HEADER@
  16. #endif
  17. @PRAGMA_COLUMNS@
  18. /* The include_next requires a split double-inclusion guard. */
  19. #@INCLUDE_NEXT@ @NEXT_FLOAT_H@
  20. #ifndef _@GUARD_PREFIX@_FLOAT_H
  21. #define _@GUARD_PREFIX@_FLOAT_H
  22. /* 'long double' properties. */
  23. #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
  24. /* Number of mantissa units, in base FLT_RADIX. */
  25. # undef LDBL_MANT_DIG
  26. # define LDBL_MANT_DIG 64
  27. /* Number of decimal digits that is sufficient for representing a number. */
  28. # undef LDBL_DIG
  29. # define LDBL_DIG 18
  30. /* x-1 where x is the smallest representable number > 1. */
  31. # undef LDBL_EPSILON
  32. # define LDBL_EPSILON 1.0842021724855044340E-19L
  33. /* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
  34. # undef LDBL_MIN_EXP
  35. # define LDBL_MIN_EXP (-16381)
  36. /* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
  37. # undef LDBL_MAX_EXP
  38. # define LDBL_MAX_EXP 16384
  39. /* Minimum positive normalized number. */
  40. # undef LDBL_MIN
  41. # define LDBL_MIN 3.3621031431120935063E-4932L
  42. /* Maximum representable finite number. */
  43. # undef LDBL_MAX
  44. # define LDBL_MAX 1.1897314953572317650E+4932L
  45. /* Minimum e such that 10^e is in the range of normalized numbers. */
  46. # undef LDBL_MIN_10_EXP
  47. # define LDBL_MIN_10_EXP (-4931)
  48. /* Maximum e such that 10^e is in the range of representable finite numbers. */
  49. # undef LDBL_MAX_10_EXP
  50. # define LDBL_MAX_10_EXP 4932
  51. #endif
  52. /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
  53. precision in the compiler but 64 bits of precision at runtime. See
  54. <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>. */
  55. #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
  56. /* Number of mantissa units, in base FLT_RADIX. */
  57. # undef LDBL_MANT_DIG
  58. # define LDBL_MANT_DIG 64
  59. /* Number of decimal digits that is sufficient for representing a number. */
  60. # undef LDBL_DIG
  61. # define LDBL_DIG 18
  62. /* x-1 where x is the smallest representable number > 1. */
  63. # undef LDBL_EPSILON
  64. # define LDBL_EPSILON 1.084202172485504434007452800869941711426e-19L /* 2^-63 */
  65. /* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
  66. # undef LDBL_MIN_EXP
  67. # define LDBL_MIN_EXP (-16381)
  68. /* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
  69. # undef LDBL_MAX_EXP
  70. # define LDBL_MAX_EXP 16384
  71. /* Minimum positive normalized number. */
  72. # undef LDBL_MIN
  73. # define LDBL_MIN 3.362103143112093506262677817321752E-4932L /* = 0x1p-16382L */
  74. /* Maximum representable finite number. */
  75. # undef LDBL_MAX
  76. /* LDBL_MAX is represented as { 0xFFFFFFFF, 0xFFFFFFFF, 32766 }.
  77. But the largest literal that GCC allows us to write is
  78. 0x0.fffffffffffff8p16384L = { 0xFFFFF800, 0xFFFFFFFF, 32766 }.
  79. So, define it like this through a reference to an external variable
  80. const unsigned int LDBL_MAX[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 32766 };
  81. extern const long double LDBL_MAX;
  82. Unfortunately, this is not a constant expression. */
  83. # if !GNULIB_defined_long_double_union
  84. union gl_long_double_union
  85. {
  86. struct { unsigned int lo; unsigned int hi; unsigned int exponent; } xd;
  87. long double ld;
  88. };
  89. # define GNULIB_defined_long_double_union 1
  90. # endif
  91. extern const union gl_long_double_union gl_LDBL_MAX;
  92. # define LDBL_MAX (gl_LDBL_MAX.ld)
  93. /* Minimum e such that 10^e is in the range of normalized numbers. */
  94. # undef LDBL_MIN_10_EXP
  95. # define LDBL_MIN_10_EXP (-4931)
  96. /* Maximum e such that 10^e is in the range of representable finite numbers. */
  97. # undef LDBL_MAX_10_EXP
  98. # define LDBL_MAX_10_EXP 4932
  99. #endif
  100. /* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are
  101. wrong.
  102. On Linux/PowerPC with gcc 4.4, the value of LDBL_MAX is wrong. */
  103. #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
  104. # undef LDBL_MIN_EXP
  105. # define LDBL_MIN_EXP DBL_MIN_EXP
  106. # undef LDBL_MIN_10_EXP
  107. # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
  108. # undef LDBL_MIN
  109. # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
  110. #endif
  111. #if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
  112. # undef LDBL_MAX
  113. /* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF }.
  114. It is not easy to define:
  115. #define LDBL_MAX 1.79769313486231580793728971405302307166e308L
  116. is too small, whereas
  117. #define LDBL_MAX 1.79769313486231580793728971405302307167e308L
  118. is too large. Apparently a bug in GCC decimal-to-binary conversion.
  119. Also, I can't get values larger than
  120. #define LDBL63 ((long double) (1ULL << 63))
  121. #define LDBL882 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
  122. #define LDBL945 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
  123. #define LDBL1008 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
  124. #define LDBL_MAX (LDBL1008 * 65535.0L + LDBL945 * (long double) 9223372036821221375ULL + LDBL882 * (long double) 4611686018427387904ULL)
  125. which is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xF8000000 }.
  126. So, define it like this through a reference to an external variable
  127. const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL };
  128. extern const long double LDBL_MAX;
  129. or through a pointer cast
  130. #define LDBL_MAX \
  131. (*(const long double *) (double[]) { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL })
  132. Unfortunately, this is not a constant expression, and the latter expression
  133. does not work well when GCC is optimizing.. */
  134. # if !GNULIB_defined_long_double_union
  135. union gl_long_double_union
  136. {
  137. struct { double hi; double lo; } dd;
  138. long double ld;
  139. };
  140. # define GNULIB_defined_long_double_union 1
  141. # endif
  142. extern const union gl_long_double_union gl_LDBL_MAX;
  143. # define LDBL_MAX (gl_LDBL_MAX.ld)
  144. #endif
  145. /* On IRIX 6.5, with cc, the value of LDBL_MANT_DIG is wrong.
  146. On IRIX 6.5, with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_EPSILON
  147. are wrong. */
  148. #if defined __sgi && (LDBL_MANT_DIG >= 106)
  149. # undef LDBL_MANT_DIG
  150. # define LDBL_MANT_DIG 106
  151. # if defined __GNUC__
  152. # undef LDBL_MIN_EXP
  153. # define LDBL_MIN_EXP DBL_MIN_EXP
  154. # undef LDBL_MIN_10_EXP
  155. # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
  156. # undef LDBL_MIN
  157. # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
  158. # undef LDBL_EPSILON
  159. # define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 */
  160. # endif
  161. #endif
  162. #if @REPLACE_ITOLD@
  163. /* Pull in a function that fixes the 'int' to 'long double' conversion
  164. of glibc 2.7. */
  165. extern
  166. # ifdef __cplusplus
  167. "C"
  168. # endif
  169. void _Qp_itoq (long double *, int);
  170. static void (*_gl_float_fix_itold) (long double *, int) = _Qp_itoq;
  171. #endif
  172. #endif /* _@GUARD_PREFIX@_FLOAT_H */
  173. #endif /* _@GUARD_PREFIX@_FLOAT_H */