extra tests to find out rounding conditions
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 29 Apr 2019 19:54:30 +0000 (20:54 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 29 Apr 2019 19:54:30 +0000 (20:54 +0100)
src/add/fsqrt.py

index 2171646c51a54e7da9284105698ab18b84fe8349..9b4c32dc8b7413b7bf7538ab989e2c490c6ae835 100644 (file)
@@ -97,13 +97,16 @@ def fsqrt_test(x):
     print("x decode", s, e, m, hex(m))
 
     m |= 1<<23 # set top bit (the missing "1" from mantissa)
-    m <<= 25
+    m <<= 27
 
     sm, se = main(m, e)
-    sm >>= 1
+    lowbits = sm & 0x3
+    sm >>= 2
     sm = get_mantissa(sm)
     #sm += 2
-    print("our  sqrt", s, se, sm, hex(sm), bin(sm))
+    print("our  sqrt", s, se, sm, hex(sm), bin(sm), "lowbits", lowbits)
+    if lowbits >= 2:
+        print ("probably needs rounding (+1 on mantissa)")
 
     sq_xbits = sq_test.bits
     s, e, m = decode_fp32(sq_xbits)
@@ -134,6 +137,10 @@ if __name__ == '__main__':
     fsqrt_test(x)
     x = Float32(8.5)
     fsqrt_test(x)
+    x = Float32(3.14159265358979323)
+    fsqrt_test(x)
+    x = Float32(12.99392923123123)
+    fsqrt_test(x)
 
 """