add log2
This was SVN commit r556.
This commit is contained in:
parent
df821a7a1c
commit
1e47f64630
@ -241,6 +241,21 @@ int ilog2(const int n)
|
||||
}
|
||||
|
||||
|
||||
// return log base 2, rounded up.
|
||||
uint log2(uint x)
|
||||
{
|
||||
uint bit = 1;
|
||||
uint l = 0;
|
||||
while(bit < x)
|
||||
{
|
||||
l++;
|
||||
bit *= 2;
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
int ilog2(const float x)
|
||||
{
|
||||
u32 i = (u32&)x;
|
||||
|
@ -264,11 +264,13 @@ extern u32 read_le32(const void* p);
|
||||
|
||||
extern bool is_pow2(long n);
|
||||
|
||||
|
||||
// return -1 if not an integral power of 2,
|
||||
// otherwise the base2 logarithm
|
||||
extern int ilog2(const int n);
|
||||
|
||||
// return log base 2, rounded up.
|
||||
extern uint log2(uint x);
|
||||
|
||||
|
||||
extern uintptr_t round_up(uintptr_t val, uintptr_t multiple);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user