From: Luke Kenneth Casson Leighton Date: Tue, 30 Apr 2019 01:58:21 +0000 (+0100) Subject: minor code-shuffle on sqrt() fn X-Git-Tag: ls180-24jan2020~1099 X-Git-Url: https://git.libre-soc.org/?p=ieee754fpu.git;a=commitdiff_plain;h=7541ca979084de96ebdf292e1baa0a03af64d3fc minor code-shuffle on sqrt() fn --- diff --git a/src/add/fsqrt.py b/src/add/fsqrt.py index c88aea39..a87af61d 100644 --- a/src/add/fsqrt.py +++ b/src/add/fsqrt.py @@ -23,30 +23,24 @@ def sqrtsimple(num): def sqrt(num): D = num # D is input (from num) Q = 0 - R = 0 - r = 0 # remainder + R = 0 # remainder for i in range(64, -1, -1): # negative ranges are weird... - if (R>=0): - - R = (R<<2)|((D>>(i+i))&3) - R = R-((Q<<2)|1) #/*-Q01*/ + R = (R<<2)|((D>>(i+i))&3) + if R >= 0: + R -= ((Q<<2)|1) # -Q01 else: + R += ((Q<<2)|3) # +Q11 - R = (R<<2)|((D>>(i+i))&3) - R = R+((Q<<2)|3) #/*+Q11*/ - - if (R>=0): - Q = (Q<<1)|1 #/*new Q:*/ - else: - Q = (Q<<1)|0 #/*new Q:*/ + Q <<= 1 + if R >= 0: + Q |= 1 # new Q + if R < 0: + R = R + ((Q<<1)|1) - if (R<0): - R = R+((Q<<1)|1) - r = R - return Q, r + return Q, R # grabbed these from unit_test_single (convenience, this is just experimenting)