summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2021-09-05 00:56:45 +0200
committerjonsykkel <jonrevold@gmail.com>2021-09-06 01:22:37 +0200
commit39cf16d157c1413adf751a9865d73d1d4cb8a36d (patch)
treeaea490b5062ab0e3a869eb09bb8d2b5cd33f35f7
parentb87aa610348ad6545de43acbebdf3453bf4764b9 (diff)
downloadokeffa-39cf16d157c1413adf751a9865d73d1d4cb8a36d.tar.gz
valid bitnes
-rw-r--r--inc/okeffa/fz_lim.h11
-rw-r--r--src/fz_lim.c8
2 files changed, 19 insertions, 0 deletions
diff --git a/inc/okeffa/fz_lim.h b/inc/okeffa/fz_lim.h
new file mode 100644
index 0000000..800220a
--- /dev/null
+++ b/inc/okeffa/fz_lim.h
@@ -0,0 +1,11 @@
+#ifndef OKEFFA_FZ_LIM_H
+#define OKEFFA_FZ_LIM_H
+
+#include <okeffa/word.h>
+
+#define FZ_MIN_BITNESS 256
+#define FZ_VALIDITY_RULE_DOC "must be greater than or equal to 256, and a power of 2"
+
+wbool_t fz_valid_bitness(size_t b);
+
+#endif
diff --git a/src/fz_lim.c b/src/fz_lim.c
new file mode 100644
index 0000000..f60eb45
--- /dev/null
+++ b/src/fz_lim.c
@@ -0,0 +1,8 @@
+#include <okeffa/fz_lim.h>
+
+wbool_t fz_valid_bitness(size_t b){
+ if(b < FZ_MIN_BITNESS) return 0;
+ if((b & b-1) != 0) return 0; //not power of 2? (prev condition handles b == 0)
+ return 1;
+}
+