Make N be the smallest power of 2 larger than 3*K+1

This commit is contained in:
2022-05-26 20:54:30 -04:00
parent 480ce57afa
commit 77043e249c
4 changed files with 86 additions and 5 deletions

26
src/int_tools.c Normal file
View 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;
}