27#ifndef math_constants_hpp
28#define math_constants_hpp
32#ifdef MX_INCLUDE_BOOST
33#include <boost/math/constants/constants.hpp>
44#define MX_INTERNAL_PI_100 \
45 ( 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 )
46#define MX_INTERNAL_ROOT2_100 \
47 ( 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727 )
48#define MX_INTERNAL_LN2_100 \
49 ( 0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875 )
50#define MX_INTERNAL_ROOT3_100 \
51 ( 1.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248576 )
52#define MX_INTERNAL_HALF_ROOT3_100 \
53 ( 0.8660254037844386467637231707529361834714026269051903140279034897259665084544000185405730933786242878 )
64#ifdef MX_INCLUDE_BOOST
65 return boost::math::constants::pi<T>();
68 std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
69 "pi<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost." );
75constexpr float pi<float>()
77 return static_cast<float>( MX_INTERNAL_PI_100 );
81constexpr double pi<double>()
83 return static_cast<double>( MX_INTERNAL_PI_100 );
89 return static_cast<long double>( MX_INTERNAL_PI_100 );
96 return static_cast<__float128
>( MX_INTERNAL_PI_100 );
109#ifdef MX_INCLUDE_BOOST
110 return boost::math::constants::two_pi<T>();
113 std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
114 "two_pi<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost." );
120constexpr float two_pi<float>()
122 return static_cast<float>( 2 * MX_INTERNAL_PI_100 );
126constexpr double two_pi<double>()
128 return static_cast<double>( 2 * MX_INTERNAL_PI_100 );
134 return static_cast<long double>( 2 * MX_INTERNAL_PI_100 );
141 return static_cast<__float128
>( 2 * MX_INTERNAL_PI_100 );
154#ifdef MX_INCLUDE_BOOST
155 return boost::math::constants::half_pi<T>();
158 std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
159 "half_pi<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost." );
165constexpr float half_pi<float>()
167 return static_cast<float>( MX_INTERNAL_PI_100 ) /
static_cast<float>( 2 );
171constexpr double half_pi<double>()
173 return static_cast<double>( MX_INTERNAL_PI_100 ) /
static_cast<double>( 2 );
179 return static_cast<long double>( MX_INTERNAL_PI_100 ) /
static_cast<long double>( 2 );
186 return static_cast<__float128
>( MX_INTERNAL_PI_100 ) /
static_cast<__float128
>( 2 );
200#ifdef MX_INCLUDE_BOOST
201 return boost::math::constants::radian<T>();
204 std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
205 "rad2deg<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost." );
211constexpr float rad2deg<float>()
213 return static_cast<float>( 180 ) /
static_cast<float>( MX_INTERNAL_PI_100 );
217constexpr double rad2deg<double>()
219 return static_cast<double>( 180 ) /
static_cast<double>( MX_INTERNAL_PI_100 );
225 return static_cast<long double>( 180 ) /
static_cast<long double>( MX_INTERNAL_PI_100 );
232 return static_cast<__float128
>( 180 ) /
static_cast<__float128
>( MX_INTERNAL_PI_100 );
245#ifdef MX_INCLUDE_BOOST
246 return boost::math::constants::root_two<T>();
249 std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
250 "root_two<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost." );
256constexpr float root_two<float>()
258 return static_cast<float>( MX_INTERNAL_ROOT2_100 );
262constexpr double root_two<double>()
264 return static_cast<double>( MX_INTERNAL_ROOT2_100 );
270 return static_cast<long double>( MX_INTERNAL_ROOT2_100 );
277 return static_cast<__float128
>( MX_INTERNAL_ROOT2_100 );
290#ifdef MX_INCLUDE_BOOST
291 return boost::math::constants::ln_two<T>();
294 std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
295 "ln_two<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost." );
301constexpr float ln_two<float>()
303 return static_cast<float>( MX_INTERNAL_LN2_100 );
307constexpr double ln_two<double>()
309 return static_cast<double>( MX_INTERNAL_LN2_100 );
315 return static_cast<long double>( MX_INTERNAL_LN2_100 );
322 return static_cast<__float128
>( MX_INTERNAL_LN2_100 );
335#ifdef MX_INCLUDE_BOOST
336 return boost::math::constants::root_three<T>();
339 std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
340 "root_three<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost." );
346constexpr float root_three<float>()
348 return static_cast<float>( MX_INTERNAL_ROOT3_100 );
352constexpr double root_three<double>()
354 return static_cast<double>( MX_INTERNAL_ROOT3_100 );
360 return static_cast<long double>( MX_INTERNAL_ROOT3_100 );
367 return static_cast<__float128
>( MX_INTERNAL_ROOT3_100 );
382 std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
383 "half_root_three<T> not specialized for type T, and there is no boost equivalent." );
388constexpr float half_root_three<float>()
390 return static_cast<float>( MX_INTERNAL_HALF_ROOT3_100 );
394constexpr double half_root_three<double>()
396 return static_cast<double>( MX_INTERNAL_HALF_ROOT3_100 );
402 return static_cast<long double>( MX_INTERNAL_HALF_ROOT3_100 );
409 return static_cast<__float128
>( MX_INTERNAL_HALF_ROOT3_100 );
421#ifdef MX_INCLUDE_BOOST
422 return boost::math::constants::third<T>();
425 std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
426 "third<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost." );
432constexpr float third<float>()
434 return static_cast<float>( 1 ) /
static_cast<float>( 3 );
438constexpr double third<double>()
440 return static_cast<double>( 1 ) /
static_cast<double>( 3 );
446 return static_cast<long double>( 1 ) /
static_cast<long double>( 3 );
453template <
typename floatT>
456 return static_cast<floatT
>( 5 ) /
static_cast<floatT
>( 3 );
464template <
typename floatT>
467 return static_cast<floatT
>( 5 ) /
static_cast<floatT
>( 6 );
475template <
typename floatT>
478 return static_cast<floatT
>( 11 ) /
static_cast<floatT
>( 3 );
486template <
typename floatT>
489 return static_cast<floatT
>( 11 ) /
static_cast<floatT
>( 6 );
497template <
typename floatT>
500 return static_cast<floatT
>( 6 ) /
static_cast<floatT
>( 5 );
508template <
typename floatT>
511 return static_cast<floatT
>( 3 ) /
static_cast<floatT
>( 5 );
519template <
typename floatT>
522 return static_cast<floatT
>( 17 ) /
static_cast<floatT
>( 3 );
constexpr T pi()
Get the value of pi.
constexpr floatT six_fifths()
Return 6/5 in the specified precision.
constexpr T root_three()
Get the value of sqrt(3).
constexpr floatT eleven_sixths()
Return 11/6 in the specified precision.
constexpr floatT seventeen_thirds()
Return 17/3 in the specified precision.
constexpr floatT five_thirds()
Return 5/3 in the specified precision.
constexpr T root_two()
Get the value of sqrt(2).
constexpr floatT eleven_thirds()
Return 11/3 in the specified precision.
constexpr T ln_two()
Get the value of ln(2).
constexpr T two_pi()
Get the value of 2pi.
constexpr floatT three_fifths()
Return 3/5 in the specified precision.
constexpr T third()
Get the value of 1/3.
constexpr T half_root_three()
Get the value of sqrt(3)/2.
constexpr T half_pi()
Get the value of pi/2.
constexpr floatT five_sixths()
Return 5/6 in the specified precision.
constexpr T rad2deg()
Get the value of 180/pi.