aboutsummaryrefslogtreecommitdiff
path: root/usr/math.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/math.c')
-rw-r--r--usr/math.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/usr/math.c b/usr/math.c
new file mode 100644
index 0000000..4d50487
--- /dev/null
+++ b/usr/math.c
@@ -0,0 +1,25 @@
+unsigned long sqrt_rnd(unsigned long square)
+{
+ unsigned long op = square;
+ unsigned long res = 0;
+ unsigned long one = 1uL << 30;
+
+ while (one > op)
+ one >>= 2;
+
+ while (one != 0)
+ {
+ if (op >= res + one)
+ {
+ op = op - (res + one);
+ res = res + 2 * one;
+ }
+ res >>= 1;
+ one >>= 2;
+ }
+
+ if (one > res)
+ res++;
+
+ return res;
+}