Browse Source

Math: improve precision of double constants by one more digit.

And add comments to make sure we are not too imprecise.
pull/364/head
Vladimír Vondruš 7 years ago
parent
commit
efe2f14284
  1. 22
      src/Magnum/Math/Constants.h

22
src/Magnum/Math/Constants.h

@ -150,14 +150,17 @@ template<class> struct Constants;
template<> struct Constants<Double> { template<> struct Constants<Double> {
Constants() = delete; Constants() = delete;
static constexpr Double pi() { return 3.141592653589793; } /* 17-digit string representation gives back the same value on rountrip.
static constexpr Double piHalf() { return 1.570796326794897; } https://en.wikipedia.org/wiki/Double-precision_floating-point_format
static constexpr Double piQuarter() { return 0.785398163397448; } Values taken using Wolfram Alpha. 1.2345678901234567 */
static constexpr Double tau() { return 6.283185307179586; } static constexpr Double pi() { return 3.1415926535897932; }
static constexpr Double e() { return 2.718281828459045; } static constexpr Double piHalf() { return 1.5707963267948966; }
static constexpr Double sqrt2() { return 1.414213562373095; } static constexpr Double piQuarter() { return 0.7853981633974483; }
static constexpr Double sqrt3() { return 1.732050807568877; } static constexpr Double tau() { return 6.2831853071795864; }
static constexpr Double sqrtHalf() { return 0.707106781186547; } static constexpr Double e() { return 2.7182818284590452; }
static constexpr Double sqrt2() { return 1.4142135623730950; }
static constexpr Double sqrt3() { return 1.7320508075688773; }
static constexpr Double sqrtHalf() { return 0.7071067811865475; }
static constexpr Double nan() { return Double(NAN); } static constexpr Double nan() { return Double(NAN); }
static constexpr Double inf() { return HUGE_VAL; } static constexpr Double inf() { return HUGE_VAL; }
@ -165,6 +168,9 @@ template<> struct Constants<Double> {
template<> struct Constants<Float> { template<> struct Constants<Float> {
Constants() = delete; Constants() = delete;
/* 9-digit string representation gives back the same value on rountrip.
https://en.wikipedia.org/wiki/Single-precision_floating-point_format
Values rounded from the above. 1.23456789 */
static constexpr Float pi() { return 3.141592654f; } static constexpr Float pi() { return 3.141592654f; }
static constexpr Float piHalf() { return 1.570796327f; } static constexpr Float piHalf() { return 1.570796327f; }
static constexpr Float piQuarter() { return 0.785398163f; } static constexpr Float piQuarter() { return 0.785398163f; }

Loading…
Cancel
Save