aboutsummaryrefslogtreecommitdiff
path: root/intmath.c
diff options
context:
space:
mode:
authorJoel Kronqvist <joelkronqvist@proton.me>2024-04-10 16:54:50 +0300
committerJoel Kronqvist <joelkronqvist@proton.me>2024-04-11 16:01:36 +0300
commita793df3e2a07c65f36fb2f5f43d2c51ab0c47bf2 (patch)
tree49858b1ef415ce16c843c4fbb4ab7eccaa73033d /intmath.c
parent4ff6a08d73f0ef1e2fcb7a93a74cc6fa66c24e2b (diff)
downloadstdu-a793df3e2a07c65f36fb2f5f43d2c51ab0c47bf2.tar.gz
stdu-a793df3e2a07c65f36fb2f5f43d2c51ab0c47bf2.zip
Added help message & fixed blocksize bug
The bug was caused by integer overflow with too large precisions.
Diffstat (limited to 'intmath.c')
-rw-r--r--intmath.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/intmath.c b/intmath.c
index 9e1f3ed..a4738b9 100644
--- a/intmath.c
+++ b/intmath.c
@@ -14,6 +14,18 @@ int int_pown(unsigned int base, unsigned int exp) {
return res;
}
+int int_logn(unsigned int base, unsigned int a) {
+ unsigned int exp = 1;
+ int res = (int) base;
+ int lastres = res - 1;
+ while ((res < a) && (lastres < res)) {
+ lastres = res;
+ res *= base;
+ exp++;
+ }
+ return exp;
+}
+
unsigned long long ull_pown(unsigned int base, unsigned int exp) {
unsigned long long res = 1;
while (exp > 0) {