float.in.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* A correct <float.h>.
  2. Copyright (C) 2007-2017 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 <http://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. <http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>. */
  55. #if defined __i386__ && defined __FreeBSD__
  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.3621031431120935E-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. union gl_long_double_union
  84. {
  85. struct { unsigned int lo; unsigned int hi; unsigned int exponent; } xd;
  86. long double ld;
  87. };
  88. extern const union gl_long_double_union gl_LDBL_MAX;
  89. # define LDBL_MAX (gl_LDBL_MAX.ld)
  90. /* Minimum e such that 10^e is in the range of normalized numbers. */
  91. # undef LDBL_MIN_10_EXP
  92. # define LDBL_MIN_10_EXP (-4931)
  93. /* Maximum e such that 10^e is in the range of representable finite numbers. */
  94. # undef LDBL_MAX_10_EXP
  95. # define LDBL_MAX_10_EXP 4932
  96. #endif
  97. /* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are
  98. wrong.
  99. On Linux/PowerPC with gcc 4.4, the value of LDBL_MAX is wrong. */
  100. #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
  101. # undef LDBL_MIN_EXP
  102. # define LDBL_MIN_EXP DBL_MIN_EXP
  103. # undef LDBL_MIN_10_EXP
  104. # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
  105. # undef LDBL_MIN
  106. # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
  107. #endif
  108. #if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
  109. # undef LDBL_MAX
  110. /* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF }.
  111. It is not easy to define:
  112. #define LDBL_MAX 1.79769313486231580793728971405302307166e308L
  113. is too small, whereas
  114. #define LDBL_MAX 1.79769313486231580793728971405302307167e308L
  115. is too large. Apparently a bug in GCC decimal-to-binary conversion.
  116. Also, I can't get values larger than
  117. #define LDBL63 ((long double) (1ULL << 63))
  118. #define LDBL882 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
  119. #define LDBL945 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
  120. #define LDBL1008 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63)
  121. #define LDBL_MAX (LDBL1008 * 65535.0L + LDBL945 * (long double) 9223372036821221375ULL + LDBL882 * (long double) 4611686018427387904ULL)
  122. which is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xF8000000 }.
  123. So, define it like this through a reference to an external variable
  124. const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL };
  125. extern const long double LDBL_MAX;
  126. or through a pointer cast
  127. #define LDBL_MAX \
  128. (*(const long double *) (double[]) { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL })
  129. Unfortunately, this is not a constant expression, and the latter expression
  130. does not work well when GCC is optimizing.. */
  131. union gl_long_double_union
  132. {
  133. struct { double hi; double lo; } dd;
  134. long double ld;
  135. };
  136. extern const union gl_long_double_union gl_LDBL_MAX;
  137. # define LDBL_MAX (gl_LDBL_MAX.ld)
  138. #endif
  139. /* On IRIX 6.5, with cc, the value of LDBL_MANT_DIG is wrong.
  140. On IRIX 6.5, with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_EPSILON
  141. are wrong. */
  142. #if defined __sgi && (LDBL_MANT_DIG >= 106)
  143. # undef LDBL_MANT_DIG
  144. # define LDBL_MANT_DIG 106
  145. # if defined __GNUC__
  146. # undef LDBL_MIN_EXP
  147. # define LDBL_MIN_EXP DBL_MIN_EXP
  148. # undef LDBL_MIN_10_EXP
  149. # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
  150. # undef LDBL_MIN
  151. # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */
  152. # undef LDBL_EPSILON
  153. # define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 */
  154. # endif
  155. #endif
  156. #if @REPLACE_ITOLD@
  157. /* Pull in a function that fixes the 'int' to 'long double' conversion
  158. of glibc 2.7. */
  159. extern
  160. # ifdef __cplusplus
  161. "C"
  162. # endif
  163. void _Qp_itoq (long double *, int);
  164. static void (*_gl_float_fix_itold) (long double *, int) = _Qp_itoq;
  165. #endif
  166. #endif /* _@GUARD_PREFIX@_FLOAT_H */
  167. #endif /* _@GUARD_PREFIX@_FLOAT_H */