From 79fa96514f59e8999bbb74d66313ca13c1b3572a Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Mon, 28 Mar 2022 11:10:07 -0700 Subject: Output s rather than s^2 --- usr/math.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 usr/math.c (limited to 'usr/math.c') 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; +} -- cgit v1.2.1