Browse Source

Math: added function fma().

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
f6ae87376b
  1. 16
      src/Math/Functions.h
  2. 10
      src/Math/Test/FunctionsTest.cpp

16
src/Math/Functions.h

@ -280,6 +280,22 @@ template<std::size_t size, class T, class U> inline Vector<size, T> lerp(const V
}
#endif
/**
@brief Fused multiply-add
Computes and returns @f$ ab + c @f$.
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class T> inline T fma(const T& a, const T& b, const T& c);
#else
template<class T> inline typename std::enable_if<std::is_arithmetic<T>::value, T>::type fma(T a, T b, T c) {
return std::fma(a, b, c);
}
template<std::size_t size, class T> inline Vector<size, T> fma(const Vector<size, T>& a, const Vector<size, T>& b, const Vector<size, T>& c) {
return a*b + c;
}
#endif
/**
@brief Normalize integral value

10
src/Math/Test/FunctionsTest.cpp

@ -41,6 +41,7 @@ class FunctionsTest: public Corrade::TestSuite::Tester {
void sqrtInverted();
void clamp();
void lerp();
void fma();
void normalizeUnsigned();
void normalizeSigned();
void denormalizeUnsigned();
@ -74,6 +75,7 @@ FunctionsTest::FunctionsTest() {
&FunctionsTest::sqrtInverted,
&FunctionsTest::clamp,
&FunctionsTest::lerp,
&FunctionsTest::fma,
&FunctionsTest::normalizeUnsigned,
&FunctionsTest::normalizeSigned,
&FunctionsTest::denormalizeUnsigned,
@ -148,6 +150,14 @@ void FunctionsTest::lerp() {
CORRADE_COMPARE(Math::lerp(c, d, 0.25f), Vector3ub(4, 96, 56));
}
void FunctionsTest::fma() {
CORRADE_COMPARE(Math::fma(2.0f, 3.0f, 0.75f), 6.75f);
CORRADE_COMPARE(Math::fma(Vector3( 2.0f, 1.5f, 0.5f),
Vector3( 3.0f, 2.0f, -1.0f),
Vector3(0.75f, 0.25f, 0.1f)),
Vector3(6.75f, 3.25f, -0.4f));
}
void FunctionsTest::normalizeUnsigned() {
CORRADE_COMPARE((Math::normalize<Float, UnsignedByte>(0)), 0.0f);
CORRADE_COMPARE((Math::normalize<Float, UnsignedByte>(255)), 1.0f);

Loading…
Cancel
Save