float128_functions.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // (C) Copyright John Maddock 2021.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. // We deliberately use assert in here:
  7. //
  8. #ifndef BOOST_MP_DETAIL_FLOAT128_FUNCTIONS_HPP
  9. #define BOOST_MP_DETAIL_FLOAT128_FUNCTIONS_HPP
  10. #include <boost/multiprecision/detail/standalone_config.hpp>
  11. #ifndef BOOST_MP_STANDALONE
  12. #include <boost/cstdfloat.hpp>
  13. #if defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_CSTDFLOAT_NO_LIBQUADMATH_SUPPORT)
  14. # define BOOST_MP_HAVE_CSTDFLOAT
  15. #endif
  16. #endif
  17. #if defined(BOOST_HAS_FLOAT128)
  18. namespace boost
  19. {
  20. namespace multiprecision
  21. {
  22. namespace float128_procs
  23. {
  24. extern "C" __float128 ldexpq(__float128, int) throw();
  25. extern "C" __float128 frexpq(__float128, int*) throw();
  26. extern "C" __float128 floorq(__float128) throw();
  27. extern "C" __float128 nextafterq(__float128, __float128) throw();
  28. extern "C" int isinfq(__float128) throw();
  29. extern "C" int isnanq(__float128) throw();
  30. extern "C" __float128 strtoflt128(const char*, char**) throw();
  31. #ifdef BOOST_MP_HAVE_CSTDFLOAT
  32. using std::ldexp;
  33. using std::frexp;
  34. using std::floor;
  35. using std::nextafter;
  36. #else
  37. inline __float128 ldexp(__float128 f, int i) throw() { return ldexpq(f, i); }
  38. inline __float128 frexp(__float128 f, int* p) throw() { return frexpq(f, p); }
  39. inline __float128 floor(__float128 f) throw() { return floorq(f); }
  40. inline __float128 nextafter(__float128 a, __float128 b) throw() { return nextafterq(a, b); }
  41. #endif
  42. }
  43. namespace detail {
  44. template <class T>
  45. struct is_float128 : public std::is_same<__float128, T>
  46. {};
  47. }
  48. }
  49. }
  50. namespace boost {
  51. namespace math {
  52. inline __float128 float_next(const __float128& f)
  53. {
  54. return boost::multiprecision::float128_procs::nextafterq(f, 2 * f);
  55. }
  56. inline int (isinf)(const __float128& f)
  57. {
  58. return boost::multiprecision::float128_procs::isinfq(f);
  59. }
  60. inline int (isnan)(const __float128& f)
  61. {
  62. return boost::multiprecision::float128_procs::isnanq(f);
  63. }
  64. }}
  65. #define BOOST_MP_FLOAT128_USING using boost::multiprecision::float128_procs::ldexp; using boost::multiprecision::float128_procs::frexp; using boost::multiprecision::float128_procs::floor; using boost::multiprecision::float128_procs::nextafter; using boost::math::isinf; using boost::math::isnan;
  66. #else
  67. #define BOOST_MP_FLOAT128_USING
  68. namespace boost {
  69. namespace multiprecision {
  70. namespace detail {
  71. template <class T>
  72. struct is_float128 : public std::false_type
  73. {};
  74. }}} // namespace boost::multiprecision::detail
  75. #endif
  76. #endif // BOOST_MP_DETAIL_FLOAT128_FUNCTIONS_HPP