uClibc_fpmax.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Copyright (C) 2003 Manuel Novoa III
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2.1 of the License, or (at your option) any later version.
  7. *
  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. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with the GNU C Library; if not, write to the Free
  15. * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. * 02111-1307 USA.
  17. */
  18. /* Define a maximal floating point type, and the associated constants
  19. * that are defined for the floating point types in float.h.
  20. *
  21. * This is to support archs that are missing long double, or even double.
  22. */
  23. #ifndef _UCLIBC_FPMAX_H
  24. #define _UCLIBC_FPMAX_H
  25. #ifndef _ISOC99_SOURCE
  26. #define _ISOC99_SOURCE 1
  27. #endif
  28. #include <features.h>
  29. #include <float.h>
  30. #ifdef __UCLIBC_HAS_FLOATS__
  31. #if defined(LDBL_MANT_DIG)
  32. typedef long double __fpmax_t;
  33. #define FPMAX_TYPE 3
  34. #define FPMAX_MANT_DIG LDBL_MANT_DIG
  35. #define FPMAX_DIG LDBL_DIG
  36. #define FPMAX_EPSILON LDBL_EPSILON
  37. #define FPMAX_MIN_EXP LDBL_MIN_EXP
  38. #define FPMAX_MIN LDBL_MIN
  39. #define FPMAX_MIN_10_EXP LDBL_MIN_10_EXP
  40. #define FPMAX_MAX_EXP LDBL_MAX_EXP
  41. #define FPMAX_MAX LDBL_MAX
  42. #define FPMAX_MAX_10_EXP LDBL_MAX_10_EXP
  43. #elif defined(DBL_MANT_DIG)
  44. typedef double __fpmax_t;
  45. #define FPMAX_TYPE 2
  46. #define FPMAX_MANT_DIG DBL_MANT_DIG
  47. #define FPMAX_DIG DBL_DIG
  48. #define FPMAX_EPSILON DBL_EPSILON
  49. #define FPMAX_MIN_EXP DBL_MIN_EXP
  50. #define FPMAX_MIN DBL_MIN
  51. #define FPMAX_MIN_10_EXP DBL_MIN_10_EXP
  52. #define FPMAX_MAX_EXP DBL_MAX_EXP
  53. #define FPMAX_MAX DBL_MAX
  54. #define FPMAX_MAX_10_EXP DBL_MAX_10_EXP
  55. #elif defined(FLT_MANT_DIG)
  56. typedef float __fpmax_t;
  57. #define FPMAX_TYPE 1
  58. #define FPMAX_MANT_DIG FLT_MANT_DIG
  59. #define FPMAX_DIG FLT_DIG
  60. #define FPMAX_EPSILON FLT_EPSILON
  61. #define FPMAX_MIN_EXP FLT_MIN_EXP
  62. #define FPMAX_MIN FLT_MIN
  63. #define FPMAX_MIN_10_EXP FLT_MIN_10_EXP
  64. #define FPMAX_MAX_EXP FLT_MAX_EXP
  65. #define FPMAX_MAX FLT_MAX
  66. #define FPMAX_MAX_10_EXP FLT_MAX_10_EXP
  67. #else
  68. #error unable to determine appropriate type for __fpmax_t!
  69. #endif
  70. #ifndef DECIMAL_DIG
  71. #ifdef L___strtofpmax
  72. /* Emit warning only once. */
  73. #warning DECIMAL_DIG is not defined! If you are using gcc, it may not be defining __STDC_VERSION__ as it should.
  74. #endif
  75. #if !defined(FLT_RADIX) || (FLT_RADIX != 2)
  76. #error unable to compensate for missing DECIMAL_DIG!
  77. #endif
  78. /* ceil (1 + #mantissa * log10 (FLT_RADIX)) */
  79. #define DECIMAL_DIG (1 + (((FPMAX_MANT_DIG * 100) + 331) / 332))
  80. #endif /* DECIMAL_DIG */
  81. #if defined _LIBC && defined IS_IN_libc
  82. extern __fpmax_t __strtofpmax(const char *str, char **endptr, int exp_adjust) attribute_hidden;
  83. #ifdef __UCLIBC_HAS_XLOCALE__
  84. extern __fpmax_t __strtofpmax_l(const char *str, char **endptr, int exp_adjust,
  85. __locale_t locale_arg) attribute_hidden;
  86. #endif
  87. #ifdef __UCLIBC_HAS_WCHAR__
  88. extern __fpmax_t __wcstofpmax(const wchar_t *wcs, wchar_t **endptr,
  89. int exp_adjust) attribute_hidden;
  90. #ifdef __UCLIBC_HAS_XLOCALE__
  91. extern __fpmax_t __wcstofpmax_l(const wchar_t *wcs, wchar_t **endptr,
  92. int exp_adjust, __locale_t locale_arg) attribute_hidden;
  93. #endif
  94. #endif /* _LIBC */
  95. #endif /* __UCLIBC_HAS_WCHAR__ */
  96. /* The following checks in an __fpmax_t is either 0 or +/- infinity.
  97. *
  98. * WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!!
  99. *
  100. * This only works if __fpmax_t is the actual maximal floating point type used
  101. * in intermediate calculations. Otherwise, excess precision in the
  102. * intermediate values can cause the test to fail.
  103. *
  104. * WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!!
  105. */
  106. #define __FPMAX_ZERO_OR_INF_CHECK(x) ((x) == ((x)/4) )
  107. #endif /* __UCLIBC_HAS_FLOATS__ */
  108. #endif /* _UCLIBC_FPMAX_H */