uClibc_fpmax.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2003-2006 Manuel Novoa III
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. /* Define a maximal floating point type, and the associated constants
  7. * that are defined for the floating point types in float.h.
  8. *
  9. * This is to support archs that are missing long double, or even double.
  10. */
  11. #ifndef _UCLIBC_FPMAX_H
  12. #define _UCLIBC_FPMAX_H
  13. #include <features.h>
  14. #include <float.h>
  15. #ifdef __UCLIBC_HAS_FLOATS__
  16. #if defined(LDBL_MANT_DIG)
  17. typedef long double __fpmax_t;
  18. #define FPMAX_TYPE 3
  19. #define FPMAX_MANT_DIG LDBL_MANT_DIG
  20. #define FPMAX_DIG LDBL_DIG
  21. #define FPMAX_EPSILON LDBL_EPSILON
  22. #define FPMAX_MIN_EXP LDBL_MIN_EXP
  23. #define FPMAX_MIN LDBL_MIN
  24. #define FPMAX_MIN_10_EXP LDBL_MIN_10_EXP
  25. #define FPMAX_MAX_EXP LDBL_MAX_EXP
  26. #define FPMAX_MAX LDBL_MAX
  27. #define FPMAX_MAX_10_EXP LDBL_MAX_10_EXP
  28. #elif defined(DBL_MANT_DIG)
  29. typedef double __fpmax_t;
  30. #define FPMAX_TYPE 2
  31. #define FPMAX_MANT_DIG DBL_MANT_DIG
  32. #define FPMAX_DIG DBL_DIG
  33. #define FPMAX_EPSILON DBL_EPSILON
  34. #define FPMAX_MIN_EXP DBL_MIN_EXP
  35. #define FPMAX_MIN DBL_MIN
  36. #define FPMAX_MIN_10_EXP DBL_MIN_10_EXP
  37. #define FPMAX_MAX_EXP DBL_MAX_EXP
  38. #define FPMAX_MAX DBL_MAX
  39. #define FPMAX_MAX_10_EXP DBL_MAX_10_EXP
  40. #elif defined(FLT_MANT_DIG)
  41. typedef float __fpmax_t;
  42. #define FPMAX_TYPE 1
  43. #define FPMAX_MANT_DIG FLT_MANT_DIG
  44. #define FPMAX_DIG FLT_DIG
  45. #define FPMAX_EPSILON FLT_EPSILON
  46. #define FPMAX_MIN_EXP FLT_MIN_EXP
  47. #define FPMAX_MIN FLT_MIN
  48. #define FPMAX_MIN_10_EXP FLT_MIN_10_EXP
  49. #define FPMAX_MAX_EXP FLT_MAX_EXP
  50. #define FPMAX_MAX FLT_MAX
  51. #define FPMAX_MAX_10_EXP FLT_MAX_10_EXP
  52. #else
  53. #error unable to determine appropriate type for __fpmax_t!
  54. #endif
  55. #ifndef DECIMAL_DIG
  56. #ifdef L___strtofpmax
  57. /* Emit warning only once. */
  58. #warning DECIMAL_DIG is not defined! If you are using gcc, it may not be defining __STDC_VERSION__ as it should.
  59. #endif
  60. #if !defined(FLT_RADIX) || (FLT_RADIX != 2)
  61. #error unable to compensate for missing DECIMAL_DIG!
  62. #endif
  63. /* ceil (1 + #mantissa * log10 (FLT_RADIX)) */
  64. #define DECIMAL_DIG (1 + (((FPMAX_MANT_DIG * 100) + 331) / 332))
  65. #endif /* DECIMAL_DIG */
  66. #if defined _LIBC && defined IS_IN_libc
  67. extern __fpmax_t __strtofpmax(const char *str, char **endptr, int exp_adjust) attribute_hidden;
  68. #ifdef __UCLIBC_HAS_XLOCALE__
  69. extern __fpmax_t __strtofpmax_l(const char *str, char **endptr, int exp_adjust,
  70. __locale_t locale_arg) attribute_hidden;
  71. #endif
  72. #ifdef __UCLIBC_HAS_WCHAR__
  73. extern __fpmax_t __wcstofpmax(const wchar_t *wcs, wchar_t **endptr,
  74. int exp_adjust) attribute_hidden;
  75. #ifdef __UCLIBC_HAS_XLOCALE__
  76. extern __fpmax_t __wcstofpmax_l(const wchar_t *wcs, wchar_t **endptr,
  77. int exp_adjust, __locale_t locale_arg) attribute_hidden;
  78. #endif
  79. #endif /* __UCLIBC_HAS_WCHAR__ */
  80. #endif /* _LIBC */
  81. /* The following checks in an __fpmax_t is either 0 or +/- infinity.
  82. *
  83. * WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!!
  84. *
  85. * This only works if __fpmax_t is the actual maximal floating point type used
  86. * in intermediate calculations. Otherwise, excess precision in the
  87. * intermediate values can cause the test to fail.
  88. *
  89. * WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!!
  90. */
  91. #define __FPMAX_ZERO_OR_INF_CHECK(x) ((x) == ((x)/4) )
  92. #endif /* __UCLIBC_HAS_FLOATS__ */
  93. #endif /* _UCLIBC_FPMAX_H */