2015-02-26 20:19:12 +01:00
|
|
|
#include "Math.h"
|
|
|
|
|
2015-04-10 21:52:30 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
2015-02-26 20:19:12 +01:00
|
|
|
namespace blobstore {
|
|
|
|
namespace onblocks {
|
|
|
|
namespace utils {
|
|
|
|
|
|
|
|
uint32_t intPow(uint32_t base, uint32_t exponent) {
|
|
|
|
uint32_t result = 1;
|
2015-03-16 18:32:37 +01:00
|
|
|
for(uint32_t i = 0; i < exponent; ++i) {
|
2015-02-26 20:19:12 +01:00
|
|
|
result *= base;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ceilDivision(uint32_t dividend, uint32_t divisor) {
|
|
|
|
return (dividend + divisor - 1)/divisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t maxZeroSubtraction(uint32_t minuend, uint32_t subtrahend) {
|
|
|
|
if (minuend < subtrahend) {
|
|
|
|
return 0u;
|
|
|
|
}
|
|
|
|
return minuend-subtrahend;
|
|
|
|
}
|
|
|
|
|
2015-04-10 21:52:30 +02:00
|
|
|
uint32_t ceilLog(uint32_t base, uint32_t value) {
|
|
|
|
return std::ceil((long double)std::log(value)/(long double)std::log(base));
|
|
|
|
}
|
|
|
|
|
2015-02-26 20:19:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|