From 5ff0e29950c0f9c37799b8515a3ec163906e67c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 12:32:44 +0100 Subject: [PATCH] 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. --- src/Math/Functions.h | 6 +++--- src/Math/Test/FunctionsTest.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index e1b5582e7..dc2ff22e6 100644 --- a/src/Math/Functions.h +++ b/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('\127'); +// Literal type is (signed) char, but we assumed unsigned char, a != 1.0f +float a = normalize('\xFF'); // b = 1.0f -float b = normalize('\127'); +float b = normalize('\xFF'); @endcode @see denormalize() diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index c0d8e2809..e0858e566 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/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(Math::denormalize(1.0l)), 1.0l); } +void FunctionsTest::normalizeTypeDeduction() { + CORRADE_COMPARE(Math::normalize('\x7F'), 1.0f); + CORRADE_COMPARE((Math::normalize('\x7F')), 1.0f); +} + void FunctionsTest::pow() { CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul); CORRADE_COMPARE(Math::pow<0>(3ul), 1ul);