From 9ab7aab32353b7d12faf1dcffb3c715a822977e3 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 28 Apr 2019 11:19:28 +0100 Subject: [PATCH] fixed sqrt bugs --- src/add/fsqrt.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 -- 2.30.2