move normalise function, add lowbits param, call it
[ieee754fpu.git] / src / add / fsqrt.py
index e0696ebcdbdce37e8df41f9dec58b42f620b5036..02449b0f75b41b0ba2e004711d9570ccca49ca3d 100644 (file)
@@ -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: