From ab35741221f0a40af60d39acf096f7ca6a79e3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 26 Nov 2015 13:29:35 +0100 Subject: [PATCH] Math: minor cleanup, reordering and test renaming. --- src/Magnum/Math/Functions.cpp | 8 +++---- src/Magnum/Math/Functions.h | 32 +++++++++++++------------- src/Magnum/Math/Test/FunctionsTest.cpp | 12 +++++----- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Magnum/Math/Functions.cpp b/src/Magnum/Math/Functions.cpp index ec4179b34..df264c893 100644 --- a/src/Magnum/Math/Functions.cpp +++ b/src/Magnum/Math/Functions.cpp @@ -27,16 +27,16 @@ namespace Magnum { namespace Math { -UnsignedInt log2(UnsignedInt number) { +UnsignedInt log(UnsignedInt base, UnsignedInt number) { UnsignedInt log = 0; - while(number >>= 1) + while(number /= base) ++log; return log; } -UnsignedInt log(UnsignedInt base, UnsignedInt number) { +UnsignedInt log2(UnsignedInt number) { UnsignedInt log = 0; - while(number /= base) + while(number >>= 1) ++log; return log; } diff --git a/src/Magnum/Math/Functions.h b/src/Magnum/Math/Functions.h index cfe77dbab..0f1d0db72 100644 --- a/src/Magnum/Math/Functions.h +++ b/src/Magnum/Math/Functions.h @@ -58,30 +58,30 @@ namespace Implementation { } /** - * @brief Integral power - * - * Returns integral power of base to the exponent. - */ +@brief Integral power + +Returns integral power of base to the exponent. +*/ template constexpr T pow(T base) { return Implementation::Pow::pow(base); } /** - * @brief Base-2 integral logarithm - * - * Returns integral logarithm of given number with base `2`. - * @see @ref log() - */ -UnsignedInt MAGNUM_EXPORT log2(UnsignedInt number); +@brief Integral logarithm -/** - * @brief Integral logarithm - * - * Returns integral logarithm of given number with given base. - * @see @ref log2() - */ +Returns integral logarithm of given number with given base. +@see @ref log2(), @ref log(T) +*/ UnsignedInt MAGNUM_EXPORT log(UnsignedInt base, UnsignedInt number); +/** +@brief Base-2 integral logarithm + +Returns integral logarithm of given number with base `2`. +@see @ref log(UnsignedInt, UnsignedInt), @ref log(T) +*/ +UnsignedInt MAGNUM_EXPORT log2(UnsignedInt number); + /** @brief Integer division with remainder diff --git a/src/Magnum/Math/Test/FunctionsTest.cpp b/src/Magnum/Math/Test/FunctionsTest.cpp index 103ae285e..adcd2200e 100644 --- a/src/Magnum/Math/Test/FunctionsTest.cpp +++ b/src/Magnum/Math/Test/FunctionsTest.cpp @@ -64,8 +64,8 @@ struct FunctionsTest: Corrade::TestSuite::Tester { void normalizeTypeDeduction(); - void pow(); - void log(); + void powIntegral(); + void logIntegral(); void log2(); void div(); void trigonometric(); @@ -112,8 +112,8 @@ FunctionsTest::FunctionsTest() { &FunctionsTest::normalizeTypeDeduction, - &FunctionsTest::pow, - &FunctionsTest::log, + &FunctionsTest::powIntegral, + &FunctionsTest::logIntegral, &FunctionsTest::log2, &FunctionsTest::div, &FunctionsTest::trigonometric, @@ -431,7 +431,7 @@ void FunctionsTest::normalizeTypeDeduction() { CORRADE_COMPARE((Math::normalize('\x7F')), 1.0f); } -void FunctionsTest::pow() { +void FunctionsTest::powIntegral() { CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul); CORRADE_COMPARE(Math::pow<0>(3ul), 1ul); CORRADE_COMPARE(Math::pow<2>(2.0f), 4.0f); @@ -441,7 +441,7 @@ void FunctionsTest::pow() { CORRADE_COMPARE(a, 125); } -void FunctionsTest::log() { +void FunctionsTest::logIntegral() { CORRADE_COMPARE(Math::log(2, 256), 8ul); CORRADE_COMPARE(Math::log(256, 2), 0ul); }