From: Aleksandar Kostovic Date: Sat, 27 Apr 2019 10:50:36 +0000 (+0200) Subject: Created the sqrt function found on wikipedia page X-Git-Tag: ls180-24jan2020~1193 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=264ec6d3b61267429026b0090047e81fe85900d5;p=ieee754fpu.git Created the sqrt function found on wikipedia page --- diff --git a/src/add/fsqrt.py b/src/add/fsqrt.py index a2065ee5..d911e340 100644 --- a/src/add/fsqrt.py +++ b/src/add/fsqrt.py @@ -1,11 +1,23 @@ def sqrt(num): - - num ** (1/2) - return num + num = 6 + res = 0 + bit = 1 << 14 + while (bit > num): + bit >>= 2 + while (bit != 0): + if (num >= res + bit): + num -= res + bit + res = (res >> 1) + bit + + else: + res >>= 1; + bit >>= 2; + + return res """ //This is the main code of integer sqrt function found here:http://verilogcodes.blogspot.com/2017/11/a-verilog-function-for-finding-square-root.html