Espresso 0.0.2a
This commit is contained in:
37
lib/math.c
Normal file
37
lib/math.c
Normal file
@ -0,0 +1,37 @@
|
||||
#include <types.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
static int ps_of_two[12] = { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
|
||||
|
||||
bool is_low_power_of_two(int n)
|
||||
{
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
if (n == ps_of_two[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t int_pow(uint64_t base, uint32_t exp)
|
||||
{
|
||||
uint64_t result = 1;
|
||||
|
||||
while (exp)
|
||||
{
|
||||
if (exp & 1)
|
||||
{
|
||||
result *= base;
|
||||
}
|
||||
|
||||
exp >>= 1;
|
||||
base *= base;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user