Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Jauslin <ian@jauslin.org>2022-05-26 20:54:30 -0400
committerIan Jauslin <ian@jauslin.org>2022-05-26 21:06:09 -0400
commit77043e249cf49fd533a1ffd6f53c0b6d6fcaaba8 (patch)
tree38ea6e714d44b996ea37a9d32a49effa62d3c6ba /src/int_tools.c
parent480ce57afa138d0daac4ae750a63ac2ee9e56bd4 (diff)
Make N be the smallest power of 2 larger than 3*K+1
Diffstat (limited to 'src/int_tools.c')
-rw-r--r--src/int_tools.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/int_tools.c b/src/int_tools.c
new file mode 100644
index 0000000..13e2cf9
--- /dev/null
+++ b/src/int_tools.c
@@ -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;
+}