maths: fix log2
This commit is contained in:
parent
c142715b66
commit
b3e72051d6
@ -48,14 +48,14 @@ log2 (T v) {
|
|||||||
"log2 is only implemented for integers");
|
"log2 is only implemented for integers");
|
||||||
|
|
||||||
T l = 0;
|
T l = 0;
|
||||||
while (v) {
|
while (v >>= 1)
|
||||||
v >>= 1;
|
++l;
|
||||||
l += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template uint8_t log2 (uint8_t);
|
||||||
|
template uint16_t log2 (uint16_t);
|
||||||
template uint32_t log2 (uint32_t);
|
template uint32_t log2 (uint32_t);
|
||||||
template uint64_t log2 (uint64_t);
|
template uint64_t log2 (uint64_t);
|
||||||
|
|
||||||
|
@ -42,5 +42,8 @@ main (int, char **) {
|
|||||||
CHECK_EQ (to_degrees (PI), 180);
|
CHECK_EQ (to_degrees (PI), 180);
|
||||||
CHECK_EQ (to_radians (180), PI);
|
CHECK_EQ (to_radians (180), PI);
|
||||||
|
|
||||||
|
CHECK_EQ (log2 (8u), 3);
|
||||||
|
CHECK_EQ (log2 (1u), 0);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user