add test for log2_approx64()
This commit is contained in:
committed by
francescomani
parent
58a2966499
commit
4b679c0793
@@ -10,12 +10,28 @@ uint8_t log2_approx_ref(uint32_t x)
|
||||
return std::round(std::log2(x));
|
||||
}
|
||||
|
||||
TEST(log2_approx_ref, complete)
|
||||
uint8_t log2_approx64_ref(unsigned long long int x)
|
||||
{
|
||||
return std::round(std::log2(static_cast<long double>(x)));
|
||||
}
|
||||
|
||||
TEST(log2_approx, complete)
|
||||
{
|
||||
for (uint32_t i = 0; i < UINT32_MAX; i++)
|
||||
EXPECT_EQ(log2_approx(i), log2_approx_ref(i));
|
||||
}
|
||||
|
||||
TEST(log2_approx64, boundaries)
|
||||
{
|
||||
for (long double i = 0; i < 64; i++) {
|
||||
unsigned long long i2 = std::pow(2.0L, i + 0.5L);
|
||||
for (unsigned long long j = -10; j <= 10; j++) {
|
||||
unsigned long long x = i2 + j;
|
||||
EXPECT_EQ(log2_approx64(x), log2_approx64_ref(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
logInit();
|
||||
|
||||
Reference in New Issue
Block a user