From: Aleksandar Kostovic Date: Sun, 28 Apr 2019 13:08:47 +0000 (+0200) Subject: Created the main function X-Git-Tag: ls180-24jan2020~1162 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d70cee8a7e37586fd89cf8a87ad802b5b808ea4f;p=ieee754fpu.git Created the main function --- diff --git a/src/add/fsqrt.py b/src/add/fsqrt.py index 948ad1cf..c76267e7 100644 --- a/src/add/fsqrt.py +++ b/src/add/fsqrt.py @@ -44,10 +44,18 @@ def sqrt(num): r = R return Q - -for Q in range(1, 26): - print(sqrt(Q), sqrtsimple(Q)) - +def main(mantissa, exponent): + if exponent & 1 != 0: + return Q(sqrt(mantissa << 1), # shift mantissa up + ((exponent - 1) / 2)) # subtract 1 from exp to compensate + else: + return Q(sqrt(mantissa), # mantissa as-is + (exponent / 2)) # no compensating needed on exp + +for Q in range(1, int(1e7)): + print(Q, sqrt(Q), sqrtsimple(Q), int(Q**0.5)) + assert int(Q**0.5) == sqrtsimple(Q), "Q sqrtsimpl fail %d" % Q + assert int(Q**0.5) == sqrt(Q), "Q sqrt fail %d" % 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 //