Make N be the smallest power of 2 larger than 3*K+1
This commit is contained in:
26
src/int_tools.c
Normal file
26
src/int_tools.c
Normal file
@ -0,0 +1,26 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user