Browse Source

Math: fix warning about literal types in normalize().

C++11 changed type of character literal (i.e. '\x7F') from int to char,
thus the documentation is wrong (also mistakenly used octal literal).
Added test to properly test the behavior.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
5ff0e29950
  1. 6
      src/Math/Functions.h
  2. 9
      src/Math/Test/FunctionsTest.cpp

6
src/Math/Functions.h

@ -231,11 +231,11 @@ value in range @f$ [0, 1] @f$ or from *signed* integral to range @f$ [-1, 1] @f$
literals, this function should be called with both template parameters
explicit, e.g.:
@code
// Even if this is character literal, integral type is 32bit, thus a != 1.0f
float a = normalize<float>('\127');
// Literal type is (signed) char, but we assumed unsigned char, a != 1.0f
float a = normalize<float>('\xFF');
// b = 1.0f
float b = normalize<float, std::int8_t>('\127');
float b = normalize<float, std::uint8_t>('\xFF');
@endcode
@see denormalize()

9
src/Math/Test/FunctionsTest.cpp

@ -37,6 +37,8 @@ class FunctionsTest: public Corrade::TestSuite::Tester {
void renormalizeUnsinged();
void renormalizeSinged();
void normalizeTypeDeduction();
void pow();
void log();
void log2();
@ -65,6 +67,8 @@ FunctionsTest::FunctionsTest() {
&FunctionsTest::renormalizeUnsinged,
&FunctionsTest::renormalizeSinged,
&FunctionsTest::normalizeTypeDeduction,
&FunctionsTest::pow,
&FunctionsTest::log,
&FunctionsTest::log2,
@ -233,6 +237,11 @@ void FunctionsTest::renormalizeSinged() {
CORRADE_COMPARE(Math::normalize<long double>(Math::denormalize<std::int64_t>(1.0l)), 1.0l);
}
void FunctionsTest::normalizeTypeDeduction() {
CORRADE_COMPARE(Math::normalize<float>('\x7F'), 1.0f);
CORRADE_COMPARE((Math::normalize<float, std::int8_t>('\x7F')), 1.0f);
}
void FunctionsTest::pow() {
CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul);
CORRADE_COMPARE(Math::pow<0>(3ul), 1ul);

Loading…
Cancel
Save