28 #ifndef math_constants_hpp
29 #define math_constants_hpp
31 #include <type_traits>
33 #ifdef MX_INCLUDE_BOOST
34 #include <boost/math/constants/constants.hpp>
42 #define MX_INTERNAL_PI_100 (3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679)
43 #define MX_INTERNAL_ROOT2_100 (1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727)
44 #define MX_INTERNAL_LN2_100 (0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875)
54 #ifdef MX_INCLUDE_BOOST
55 return boost::math::constants::pi<T>();
57 static_assert(std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
"pi<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost.");
63 constexpr
float pi<float>()
65 return static_cast<float>(MX_INTERNAL_PI_100);
69 constexpr
double pi<double>()
71 return static_cast<double>(MX_INTERNAL_PI_100);
75 constexpr
long double pi<long double>()
77 return static_cast<long double>(MX_INTERNAL_PI_100);
82 constexpr __float128 pi<__float128>()
84 return static_cast<__float128
>(MX_INTERNAL_PI_100);
96 #ifdef MX_INCLUDE_BOOST
97 return boost::math::constants::two_pi<T>();
99 static_assert(std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
"two_pi<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost.");
105 constexpr
float two_pi<float>()
107 return static_cast<float>(2*MX_INTERNAL_PI_100);
111 constexpr
double two_pi<double>()
113 return static_cast<double>(2*MX_INTERNAL_PI_100);
117 constexpr
long double two_pi<long double>()
119 return static_cast<long double>(2*MX_INTERNAL_PI_100);
124 constexpr __float128 two_pi<__float128>()
126 return static_cast<__float128
>(2*MX_INTERNAL_PI_100);
138 #ifdef MX_INCLUDE_BOOST
139 return boost::math::constants::half_pi<T>();
141 static_assert(std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
"half_pi<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost.");
147 constexpr
float half_pi<float>()
149 return static_cast<float>(MX_INTERNAL_PI_100)/
static_cast<float>(2);
153 constexpr
double half_pi<double>()
155 return static_cast<double>(MX_INTERNAL_PI_100)/
static_cast<double>(2);
159 constexpr
long double half_pi<long double>()
161 return static_cast<long double>(MX_INTERNAL_PI_100)/
static_cast<long double>(2);
166 constexpr __float128 half_pi<__float128>()
168 return static_cast<__float128
>(MX_INTERNAL_PI_100)/
static_cast<__float128
>(2);;
180 #ifdef MX_INCLUDE_BOOST
181 return boost::math::constants::radian<T>();
183 static_assert(std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
"rad2deg<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost.");
189 constexpr
float rad2deg<float>()
191 return static_cast<float>(180)/
static_cast<float>(MX_INTERNAL_PI_100);
195 constexpr
double rad2deg<double>()
197 return static_cast<double>(180)/
static_cast<double>(MX_INTERNAL_PI_100);
201 constexpr
long double rad2deg<long double>()
203 return static_cast<long double>(180)/
static_cast<long double>(MX_INTERNAL_PI_100);
208 constexpr __float128 rad2deg<__float128>()
210 return static_cast<__float128
>(180)/
static_cast<__float128
>(MX_INTERNAL_PI_100);
222 #ifdef MX_INCLUDE_BOOST
223 return boost::math::constants::root_two<T>();
225 static_assert(std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
"root_two<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost.");
231 constexpr
float root_two<float>()
233 return static_cast<float>(MX_INTERNAL_ROOT2_100);
237 constexpr
double root_two<double>()
239 return static_cast<double>(MX_INTERNAL_ROOT2_100);
243 constexpr
long double root_two<long double>()
245 return static_cast<long double>(MX_INTERNAL_ROOT2_100);
250 constexpr __float128 root_two<__float128>()
252 return static_cast<__float128
>(MX_INTERNAL_ROOT2_100);
265 #ifdef MX_INCLUDE_BOOST
266 return boost::math::constants::ln_two<T>();
268 static_assert(std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
"ln_two<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost.");
274 constexpr
float ln_two<float>()
276 return static_cast<float>(MX_INTERNAL_LN2_100);
280 constexpr
double ln_two<double>()
282 return static_cast<double>(MX_INTERNAL_LN2_100);
286 constexpr
long double ln_two<long double>()
288 return static_cast<long double>(MX_INTERNAL_LN2_100);
293 constexpr __float128 ln_two<__float128>()
295 return static_cast<__float128
>(MX_INTERNAL_LN2_100);
308 #ifdef MX_INCLUDE_BOOST
309 return boost::math::constants::third<T>();
311 static_assert(std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
"third<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost.");
317 constexpr
float third<float>()
319 return static_cast<float>(1)/
static_cast<float>(3);
323 constexpr
double third<double>()
325 return static_cast<double>(1)/
static_cast<double>(3);
329 constexpr
long double third<long double>()
331 return static_cast<long double>(1)/
static_cast<long double>(3);
339 template<
typename floatT>
342 return static_cast<floatT
>(5)/
static_cast<floatT
>(3);
351 template<
typename floatT>
354 return static_cast<floatT
>(5)/
static_cast<floatT
>(6);
362 template<
typename floatT>
365 return static_cast<floatT
>(11)/
static_cast<floatT
>(3);
373 template<
typename floatT>
376 return static_cast<floatT
>(11)/
static_cast<floatT
>(6);
384 template<
typename floatT>
387 return static_cast<floatT
>(6)/
static_cast<floatT
>(5);
395 template<
typename floatT>
398 return static_cast<floatT
>(3)/
static_cast<floatT
>(5);
406 template<
typename floatT>
409 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 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_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.