From: Luke Kenneth Casson Leighton Date: Sun, 28 Apr 2019 10:19:28 +0000 (+0100) Subject: fixed sqrt bugs X-Git-Tag: ls180-24jan2020~1164 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9ab7aab32353b7d12faf1dcffb3c715a822977e3;p=ieee754fpu.git fixed sqrt bugs --- diff --git a/src/add/fsqrt.py b/src/add/fsqrt.py index 3a2e999e..948ad1cf 100644 --- a/src/add/fsqrt.py +++ b/src/add/fsqrt.py @@ -1,5 +1,4 @@ -def sqrt(num): - """ +def sqrtsimple(num): res = 0 bit = 1 << 14 @@ -15,13 +14,14 @@ def sqrt(num): bit >>= 2 return res - """ - r = None - D = None + + +def sqrt(num): + D = num # D is input (from num) Q = 0 R = 0 - for i in range(15): - i -= 1 + r = 0 # remainder + for i in range(15, -1, -1): # negative ranges are weird... if (R>=0): @@ -45,8 +45,8 @@ def sqrt(num): return Q -for Q in range(1,20): - print(sqrt(Q)) +for Q in range(1, 26): + print(sqrt(Q), sqrtsimple(Q)) """ //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