This was SVN commit r556.
This commit is contained in:
janwas 2004-06-19 14:43:31 +00:00
parent df821a7a1c
commit 1e47f64630
2 changed files with 18 additions and 1 deletions

View File

@ -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;

View File

@ -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);