Browse Source

Math: added Constants::sqrtHalf().

pull/268/merge
Vladimír Vondruš 8 years ago
parent
commit
1a253af761
  1. 2
      doc/changelog.dox
  2. 15
      src/Magnum/Math/Constants.h
  3. 2
      src/Magnum/Math/Test/ConstantsTest.cpp

2
doc/changelog.dox

@ -106,7 +106,7 @@ See also:
integral centered ranges
- @ref Math::Range is now constructible from a @ref std::pair of values,
making it usable in combination with @ref Math::minmax(), for example
- Added @ref Math::Constants::piQuarter()
- Added @ref Math::Constants::piQuarter(), @ref Math::Constants::sqrtHalf()
- Added a convenience function @ref Math::select() as a constant
interpolation counterpart to @ref Math::lerp()
- Added a convenience function @ref Math::planeEquation() to aid with passing

15
src/Magnum/Math/Constants.h

@ -71,7 +71,8 @@ template<class T> struct Constants {
* @f[
* \frac{\pi}{4} = 45 \degree
* @f]
* @see @ref pi(), @ref piHalf(), @ref tau(), @ref Deg, @ref Rad
* @see @ref pi(), @ref piHalf(), @ref sqrtHalf(), @ref tau(), @ref Deg,
* @ref Rad
*/
static constexpr T piQuarter();
@ -117,6 +118,16 @@ template<class T> struct Constants {
*/
static constexpr T sqrt3();
/**
* @brief Square root of @f$ \frac{1}{2} @f$
*
* @f[
* \frac{\sqrt{2}}{2} = \frac{1}{\sqrt{2}} = \sin(45 \degree) = \cos(45 \degree)
* @f]
* @see @ref sqrt2(), @ref sqrt3(), @ref piQuarter()
*/
static constexpr T sqrtHalf();
/**
* @brief Quiet NaN
*
@ -144,6 +155,7 @@ template<> struct Constants<Double> {
static constexpr Double e() { return 2.718281828459045; }
static constexpr Double sqrt2() { return 1.414213562373095; }
static constexpr Double sqrt3() { return 1.732050807568877; }
static constexpr Double sqrtHalf() { return 0.707106781186547; }
static constexpr Double nan() { return Double(NAN); }
static constexpr Double inf() { return HUGE_VAL; }
@ -158,6 +170,7 @@ template<> struct Constants<Float> {
static constexpr Float e() { return 2.718281828f; }
static constexpr Float sqrt2() { return 1.414213562f; }
static constexpr Float sqrt3() { return 1.732050808f; }
static constexpr Float sqrtHalf() { return 0.707106781f; }
static constexpr Float nan() { return NAN; }
static constexpr Float inf() { return HUGE_VALF; }

2
src/Magnum/Math/Test/ConstantsTest.cpp

@ -51,8 +51,10 @@ template<class T> void ConstantsTest::constants() {
{
constexpr T a = Constants<T>::sqrt2();
constexpr T b = Constants<T>::sqrt3();
constexpr T c = Constants<T>::sqrtHalf();
CORRADE_COMPARE(Math::pow<2>(a), T(2));
CORRADE_COMPARE(Math::pow<2>(b), T(3));
CORRADE_COMPARE(Math::pow<2>(c), T(0.5));
} {
constexpr T a = Constants<T>::pi();
constexpr T b = Constants<T>::piHalf();

Loading…
Cancel
Save