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 {
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;
}

32
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<UnsignedInt exponent, class T> constexpr T pow(T base) {
return Implementation::Pow<exponent>::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

12
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<Float, Byte>('\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);
}

Loading…
Cancel
Save