X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fadd%2Ffsqrt.py;h=02449b0f75b41b0ba2e004711d9570ccca49ca3d;hb=6bff1a997f3846872cf489c24b5c01426c4dc97c;hp=a87af61db4ded516df1f93d6cb3af933d6318af3;hpb=7541ca979084de96ebdf292e1baa0a03af64d3fc;p=ieee754fpu.git diff --git a/src/add/fsqrt.py b/src/add/fsqrt.py index a87af61d..02449b0f 100644 --- a/src/add/fsqrt.py +++ b/src/add/fsqrt.py @@ -22,7 +22,7 @@ def sqrtsimple(num): def sqrt(num): D = num # D is input (from num) - Q = 0 + Q = 0 # quotient R = 0 # remainder for i in range(64, -1, -1): # negative ranges are weird... @@ -80,6 +80,15 @@ def main(mantissa, exponent): return m, r, exponent >> 1 +#normalization function +def normalise(s, m, e, lowbits): + if (lowbits >= 2): + m += 1 + if get_mantissa(m) == ((1<<24)-1): + e += 1 + return s, m, e + + def fsqrt_test(x): xbits = x.bits @@ -99,6 +108,9 @@ def fsqrt_test(x): sm >>= 2 sm = get_mantissa(sm) #sm += 2 + + s, sm, se = normalise(s, sm, se, lowbits) + print("our sqrt", s, se, sm, hex(sm), bin(sm), "lowbits", lowbits, "rem", hex(sr)) if lowbits >= 2: @@ -140,6 +152,9 @@ if __name__ == '__main__': x = Float32(0.123456) fsqrt_test(x) + + + """ Notes: