// Distributed under the Boost Software License Version 1.0 https://www.boost.org/LICENSE_1_0.txt // Copyright Gero Peterhoff #ifndef BOOST_MATH_CONSTANTS_MORE_HPP #define BOOST_MATH_CONSTANTS_MORE_HPP #include #include #include #include namespace boost { namespace multiprecision { #if defined(BOOST_MP_USE_FLOAT128) || defined(BOOST_MP_USE_QUAD) #define BOOST_MP_USE_QUADMATH #endif template struct is_mp_float128 : public std::false_type{}; template <> struct is_mp_float128 : public std::integral_constant < bool, #if defined(BOOST_MP_USE_QUADMATH) true #else false #endif > {}; } // multiprecision namespace math { namespace constants { #define BOOST_MAKE_MATH_CONSTANT(NAME, VALUE_F, VALUE_S) \ namespace values \ { \ /* constexpr struct */ \ template ::value || boost::multiprecision::is_mp_float128::value> struct NAME \ { \ inline static constexpr Type make_value() noexcept \ { \ /* return Type(BOOST_FLOATMAX_C(VALUE_F)); */ \ BOOST_IF_CONSTEXPR (boost::is_float128::value || boost::multiprecision::is_mp_float128::value) return BOOST_FLOAT128_C_OR_ZERO(VALUE_F); \ else BOOST_IF_CONSTEXPR (boost::is_float80::value) return BOOST_FLOAT80_C_OR_ZERO(VALUE_F); \ else BOOST_IF_CONSTEXPR (boost::is_float64::value) return BOOST_FLOAT64_C_OR_ZERO(VALUE_F); \ else BOOST_IF_CONSTEXPR (boost::is_float32::value) return BOOST_FLOAT32_C_OR_ZERO(VALUE_F); \ else BOOST_IF_CONSTEXPR (boost::is_float16::value) return BOOST_FLOAT16_C_OR_ZERO(VALUE_F); \ else BOOST_IF_CONSTEXPR (boost::is_bfloat16::value) return BOOST_BFLOAT16_C_OR_ZERO(VALUE_F); \ else return 0; \ } \ static constexpr Type value = make_value(); \ static_assert(value != 0, "invalid"); \ }; \ /* non-constexpr struct */ \ template struct NAME \ { \ const Type value = Type(VALUE_S); \ }; \ } /* values */ \ /* getter */ \ template \ inline constexpr Type NAME() noexcept { return values::NAME{}.value; } BOOST_MAKE_MATH_CONSTANT(my_pi, 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651, "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651") BOOST_MAKE_MATH_CONSTANT(psi, -0.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408808, "-0.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408808") BOOST_MAKE_MATH_CONSTANT(root_five, 2.23606797749978969640917366873127631939404588074105727133751596842430563183423686268724850378930568695068359375, "2.23606797749978969640917366873127631939404588074105727133751596842430563183423686268724850378930568695068359375") //BOOST_DEFINE_MATH_CONSTANT(psi, -0.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408808, "-0.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408808") //BOOST_DEFINE_MATH_CONSTANT(root_five, 2.23606797749978969640917366873127631939404588074105727133751596842430563183423686268724850378930568695068359375, "2.23606797749978969640917366873127631939404588074105727133751596842430563183423686268724850378930568695068359375") } // constants } // math } // boost #endif // BOOST_MATH_CONSTANTS_MORE_HPP