Updated Inf and NaN parts of normalise function
[ieee754fpu.git] / src / ieee754 / fpsqrt / fsqrt.py
index 02449b0f75b41b0ba2e004711d9570ccca49ca3d..f7410703643e763c0ad5c43c57e6c39b3c12e71e 100644 (file)
@@ -86,6 +86,26 @@ def normalise(s, m, e, lowbits):
         m += 1
     if get_mantissa(m) == ((1<<24)-1):
         e += 1
+
+    # this is 2nd-stage normalisation.  can move it to a separate fn.
+
+    #if the num is NaN, then adjust (normalised NaN rather than de-normed NaN)
+    if (e == 128 & m !=0):
+        # these are in IEEE754 format, this function returns s,e,m not z
+        s = 1           # sign (so, s=1)
+        e = 255         # exponent (minus 128, so e = 127
+        m = 1<<22     # high bit of mantissa, so m = 1<<22 i think
+        m = 1
+        m = 1<<22     # rest of mantissa is zero, so m = 1<<22 is good.
+        m = 0
+
+    #if the num is Inf, then adjust (to normalised +/-INF)
+    if (e == 128):
+        # these are in IEEE754 format, this function returns s,e,m not z
+        s = 1       # s is already s, so do nothing to s.
+        m = 255  # have to subtract 128, so e = 127 (again)
+        m = 0     # mantissa... so m=0
+
     return s, m, e