cstdfloat_limits.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright Christopher Kormanyos 2014.
  3. // Copyright John Maddock 2014.
  4. // Copyright Paul Bristow 2014.
  5. // Distributed under the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt
  7. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // Implement quadruple-precision std::numeric_limits<> support.
  10. #ifndef BOOST_MATH_CSTDFLOAT_LIMITS_2014_01_09_HPP_
  11. #define BOOST_MATH_CSTDFLOAT_LIMITS_2014_01_09_HPP_
  12. #include <boost/math/cstdfloat/cstdfloat_types.hpp>
  13. #if defined(__GNUC__) && defined(BOOST_MATH_USE_FLOAT128)
  14. //
  15. // This is the only way we can avoid
  16. // warning: non-standard suffix on floating constant [-Wpedantic]
  17. // when building with -Wall -pedantic. Neither __extension__
  18. // nor #pragma diagnostic ignored work :(
  19. //
  20. #pragma GCC system_header
  21. #endif
  22. #if defined(BOOST_CSTDFLOAT_HAS_INTERNAL_FLOAT128_T) && defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_CSTDFLOAT_NO_LIBQUADMATH_SUPPORT) && (!defined(_GLIBCXX_RELEASE) || (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 14))
  23. #include <limits>
  24. #include <boost/math/tools/nothrow.hpp>
  25. // Define the name of the global quadruple-precision function to be used for
  26. // calculating quiet_NaN() in the specialization of std::numeric_limits<>.
  27. #if defined(__INTEL_COMPILER)
  28. #define BOOST_CSTDFLOAT_FLOAT128_SQRT __sqrtq
  29. #elif defined(__GNUC__)
  30. #define BOOST_CSTDFLOAT_FLOAT128_SQRT sqrtq
  31. #endif
  32. // Forward declaration of the quadruple-precision square root function.
  33. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_SQRT(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  34. namespace std
  35. {
  36. template<>
  37. class numeric_limits<boost::math::cstdfloat::detail::float_internal128_t>
  38. {
  39. public:
  40. static constexpr bool is_specialized = true;
  41. static boost::math::cstdfloat::detail::float_internal128_t (min) () noexcept { return BOOST_CSTDFLOAT_FLOAT128_MIN; }
  42. static boost::math::cstdfloat::detail::float_internal128_t (max) () noexcept { return BOOST_CSTDFLOAT_FLOAT128_MAX; }
  43. static boost::math::cstdfloat::detail::float_internal128_t lowest() noexcept { return -(max)(); }
  44. static constexpr int digits = 113;
  45. static constexpr int digits10 = 33;
  46. static constexpr int max_digits10 = 36;
  47. static constexpr bool is_signed = true;
  48. static constexpr bool is_integer = false;
  49. static constexpr bool is_exact = false;
  50. static constexpr int radix = 2;
  51. static boost::math::cstdfloat::detail::float_internal128_t epsilon () { return BOOST_CSTDFLOAT_FLOAT128_EPS; }
  52. static boost::math::cstdfloat::detail::float_internal128_t round_error() { return BOOST_FLOAT128_C(0.5); }
  53. static constexpr int min_exponent = -16381;
  54. static constexpr int min_exponent10 = static_cast<int>((min_exponent * 301L) / 1000L);
  55. static constexpr int max_exponent = +16384;
  56. static constexpr int max_exponent10 = static_cast<int>((max_exponent * 301L) / 1000L);
  57. static constexpr bool has_infinity = true;
  58. static constexpr bool has_quiet_NaN = true;
  59. static constexpr bool has_signaling_NaN = false;
  60. static constexpr float_denorm_style has_denorm = denorm_present;
  61. static constexpr bool has_denorm_loss = false;
  62. static boost::math::cstdfloat::detail::float_internal128_t infinity () { return BOOST_FLOAT128_C(1.0) / BOOST_FLOAT128_C(0.0); }
  63. static boost::math::cstdfloat::detail::float_internal128_t quiet_NaN () { return -(::BOOST_CSTDFLOAT_FLOAT128_SQRT(BOOST_FLOAT128_C(-1.0))); }
  64. static boost::math::cstdfloat::detail::float_internal128_t signaling_NaN() { return BOOST_FLOAT128_C(0.0); }
  65. static boost::math::cstdfloat::detail::float_internal128_t denorm_min () { return BOOST_CSTDFLOAT_FLOAT128_DENORM_MIN; }
  66. static constexpr bool is_iec559 = true;
  67. static constexpr bool is_bounded = true;
  68. static constexpr bool is_modulo = false;
  69. static constexpr bool traps = false;
  70. static constexpr bool tinyness_before = false;
  71. static constexpr float_round_style round_style = round_to_nearest;
  72. };
  73. } // namespace std
  74. #endif // Not BOOST_CSTDFLOAT_NO_LIBQUADMATH_SUPPORT (i.e., the user would like to have libquadmath support)
  75. #endif // BOOST_MATH_CSTDFLOAT_LIMITS_2014_01_09_HPP_