add fpclass pipeline (1st version)
[ieee754fpu.git] / src / ieee754 / fpsqrt / fsqrt.py
index 15f1555d969098246dc9df4bf1f3ffce812d6958..3f63ce780fce0056db0b8937ad4de335024f8faa 100644 (file)
@@ -86,17 +86,22 @@ def normalise(s, m, e, lowbits):
         m += 1
     if get_mantissa(m) == ((1<<24)-1):
         e += 1
-    #if the num is NaN, than adjust
+
+    # 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):
-        z[31] = 1
-        z[30:23] = 255
-        z[22] = 1
-        z[21:0] = 0
-    #if the num is Inf, then adjust
+        # these are in IEEE754 format, this function returns s,e,m not z
+        s = 1           # sign (so, s=1)
+        e = 128         # exponent (minus 127, so e = 128
+        m = 1<<22     # high bit of mantissa, so m = 1<<22 i think
+
+    #if the num is Inf, then adjust (to normalised +/-INF)
     if (e == 128):
-        z[31] = s
-        z[30:23] = 255
-        z[22:0] = 0
+        # these are in IEEE754 format, this function returns s,e,m not z
+        s = 1       # s is already s, so do nothing to s.
+        e = 128  # have to subtract 127, so e = 128 (again)
+        m = 0     # mantissa... so m=0
 
     return s, m, e