Browse Source

Math: minor cleanup, reordering and test renaming.

pull/122/merge
Vladimír Vondruš 11 years ago
parent
commit
ab35741221
  1. 8
      src/Magnum/Math/Functions.cpp
  2. 32
      src/Magnum/Math/Functions.h
  3. 12
      src/Magnum/Math/Test/FunctionsTest.cpp

8
src/Magnum/Math/Functions.cpp

@ -27,16 +27,16 @@
namespace Magnum { namespace Math { namespace Magnum { namespace Math {
UnsignedInt log2(UnsignedInt number) { UnsignedInt log(UnsignedInt base, UnsignedInt number) {
UnsignedInt log = 0; UnsignedInt log = 0;
while(number >>= 1) while(number /= base)
++log; ++log;
return log; return log;
} }
UnsignedInt log(UnsignedInt base, UnsignedInt number) { UnsignedInt log2(UnsignedInt number) {
UnsignedInt log = 0; UnsignedInt log = 0;
while(number /= base) while(number >>= 1)
++log; ++log;
return log; return log;
} }

32
src/Magnum/Math/Functions.h

@ -58,30 +58,30 @@ namespace Implementation {
} }
/** /**
* @brief Integral power @brief Integral power
*
* Returns integral power of base to the exponent. Returns integral power of base to the exponent.
*/ */
template<UnsignedInt exponent, class T> constexpr T pow(T base) { template<UnsignedInt exponent, class T> constexpr T pow(T base) {
return Implementation::Pow<exponent>::pow(base); return Implementation::Pow<exponent>::pow(base);
} }
/** /**
* @brief Base-2 integral logarithm @brief Integral logarithm
*
* Returns integral logarithm of given number with base `2`.
* @see @ref log()
*/
UnsignedInt MAGNUM_EXPORT log2(UnsignedInt number);
/** Returns integral logarithm of given number with given base.
* @brief Integral logarithm @see @ref log2(), @ref log(T)
* */
* Returns integral logarithm of given number with given base.
* @see @ref log2()
*/
UnsignedInt MAGNUM_EXPORT log(UnsignedInt base, UnsignedInt number); 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 @brief Integer division with remainder

12
src/Magnum/Math/Test/FunctionsTest.cpp

@ -64,8 +64,8 @@ struct FunctionsTest: Corrade::TestSuite::Tester {
void normalizeTypeDeduction(); void normalizeTypeDeduction();
void pow(); void powIntegral();
void log(); void logIntegral();
void log2(); void log2();
void div(); void div();
void trigonometric(); void trigonometric();
@ -112,8 +112,8 @@ FunctionsTest::FunctionsTest() {
&FunctionsTest::normalizeTypeDeduction, &FunctionsTest::normalizeTypeDeduction,
&FunctionsTest::pow, &FunctionsTest::powIntegral,
&FunctionsTest::log, &FunctionsTest::logIntegral,
&FunctionsTest::log2, &FunctionsTest::log2,
&FunctionsTest::div, &FunctionsTest::div,
&FunctionsTest::trigonometric, &FunctionsTest::trigonometric,
@ -431,7 +431,7 @@ void FunctionsTest::normalizeTypeDeduction() {
CORRADE_COMPARE((Math::normalize<Float, Byte>('\x7F')), 1.0f); CORRADE_COMPARE((Math::normalize<Float, Byte>('\x7F')), 1.0f);
} }
void FunctionsTest::pow() { void FunctionsTest::powIntegral() {
CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul); CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul);
CORRADE_COMPARE(Math::pow<0>(3ul), 1ul); CORRADE_COMPARE(Math::pow<0>(3ul), 1ul);
CORRADE_COMPARE(Math::pow<2>(2.0f), 4.0f); CORRADE_COMPARE(Math::pow<2>(2.0f), 4.0f);
@ -441,7 +441,7 @@ void FunctionsTest::pow() {
CORRADE_COMPARE(a, 125); CORRADE_COMPARE(a, 125);
} }
void FunctionsTest::log() { void FunctionsTest::logIntegral() {
CORRADE_COMPARE(Math::log(2, 256), 8ul); CORRADE_COMPARE(Math::log(2, 256), 8ul);
CORRADE_COMPARE(Math::log(256, 2), 0ul); CORRADE_COMPARE(Math::log(256, 2), 0ul);
} }

Loading…
Cancel
Save