fpioconst.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Header file for constants used in floating point <-> decimal conversions.
  2. Copyright (C) 1995-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _FPIOCONST_H
  16. #define _FPIOCONST_H
  17. #include <float.h>
  18. #include <math.h>
  19. #include <gmp.h>
  20. /* These values are used by __printf_fp, where they are noncritical (if the
  21. value is not large enough, it will just be slower); and by
  22. strtof/strtod/strtold, where it is critical (it's used for overflow
  23. detection).
  24. XXX These should be defined in <float.h>. For the time being, we have the
  25. IEEE754 values here. */
  26. #if !defined __NO_LONG_DOUBLE_MATH && __LDBL_MAX_EXP__ > 1024
  27. # define LDBL_MAX_10_EXP_LOG 12 /* = floor(log_2(LDBL_MAX_10_EXP)) */
  28. #else
  29. # define LDBL_MAX_10_EXP_LOG 8 /* = floor(log_2(LDBL_MAX_10_EXP)) */
  30. #endif
  31. #define DBL_MAX_10_EXP_LOG 8 /* = floor(log_2(DBL_MAX_10_EXP)) */
  32. #define FLT_MAX_10_EXP_LOG 5 /* = floor(log_2(FLT_MAX_10_EXP)) */
  33. /* On some machines, _Float128 may be ABI-distinct from long double (e.g
  34. IBM extended precision). */
  35. #include <bits/floatn.h>
  36. #if __HAVE_DISTINCT_FLOAT128
  37. # define FLT128_MAX_10_EXP_LOG 12 /* = floor(log_2(FLT128_MAX_10_EXP)) */
  38. #endif
  39. /* For strtold, we need powers of 10 up to floor (log_2 (LDBL_MANT_DIG
  40. - LDBL_MIN_EXP + 2)). When _Float128 is enabled in libm and it is
  41. ABI-distinct from long double (e.g. on powerpc64le), we also need powers
  42. of 10 up to floor (log_2 (FLT128_MANT_DIG - FLT128_MIN_EXP + 2)). */
  43. #define FPIOCONST_HAVE_EXTENDED_RANGE \
  44. ((!defined __NO_LONG_DOUBLE_MATH && __LDBL_MAX_EXP__ > 1024) \
  45. || __HAVE_DISTINCT_FLOAT128)
  46. #if FPIOCONST_HAVE_EXTENDED_RANGE
  47. # define FPIOCONST_POW10_ARRAY_SIZE 15
  48. #else
  49. # define FPIOCONST_POW10_ARRAY_SIZE 11
  50. #endif
  51. /* The array with the number representation. */
  52. extern const mp_limb_t __tens[] attribute_hidden;
  53. /* Table of powers of ten. This is used by __printf_fp and by
  54. strtof/strtod/strtold. */
  55. struct mp_power
  56. {
  57. size_t arrayoff; /* Offset in `__tens'. */
  58. mp_size_t arraysize; /* Size of the array. */
  59. int p_expo; /* Exponent of the number 10^(2^i). */
  60. int m_expo; /* Exponent of the number 10^-(2^i-1). */
  61. };
  62. extern const struct mp_power _fpioconst_pow10[FPIOCONST_POW10_ARRAY_SIZE]
  63. attribute_hidden;
  64. /* The constants in the array `_fpioconst_pow10' have an offset. */
  65. #if BITS_PER_MP_LIMB == 32
  66. # define _FPIO_CONST_OFFSET 2
  67. #else
  68. # define _FPIO_CONST_OFFSET 1
  69. #endif
  70. #endif /* fpioconst.h */