27 lines
308 B
C
27 lines
308 B
C
|
#include <math.h>
|
||
|
#include "int_tools.h"
|
||
|
|
||
|
// return smallest power of 2 that is > x
|
||
|
int smallest_pow2(
|
||
|
int x
|
||
|
){
|
||
|
return ipow(2,((int)log2(x)+1));
|
||
|
}
|
||
|
|
||
|
// integer power
|
||
|
int ipow(
|
||
|
int x,
|
||
|
int n
|
||
|
){
|
||
|
int out=1;
|
||
|
while (n>0)
|
||
|
{
|
||
|
if (n%2==1){
|
||
|
out*=x;
|
||
|
}
|
||
|
n/=2;
|
||
|
x*=x;
|
||
|
}
|
||
|
return out;
|
||
|
}
|