PyXR

c:\python24\lib \ test \ double_const.py



0001 from test.test_support import TestFailed
0002 
0003 # A test for SF bug 422177:  manifest float constants varied way too much in
0004 # precision depending on whether Python was loading a module for the first
0005 # time, or reloading it from a precompiled .pyc.  The "expected" failure
0006 # mode is that when test_import imports this after all .pyc files have been
0007 # erased, it passes, but when test_import imports this from
0008 # double_const.pyc, it fails.  This indicates a woeful loss of precision in
0009 # the marshal format for doubles.  It's also possible that repr() doesn't
0010 # produce enough digits to get reasonable precision for this box.
0011 
0012 PI    = 3.14159265358979324
0013 TWOPI = 6.28318530717958648
0014 
0015 PI_str    = "3.14159265358979324"
0016 TWOPI_str = "6.28318530717958648"
0017 
0018 # Verify that the double x is within a few bits of eval(x_str).
0019 def check_ok(x, x_str):
0020     assert x > 0.0
0021     x2 = eval(x_str)
0022     assert x2 > 0.0
0023     diff = abs(x - x2)
0024     # If diff is no larger than 3 ULP (wrt x2), then diff/8 is no larger
0025     # than 0.375 ULP, so adding diff/8 to x2 should have no effect.
0026     if x2 + (diff / 8.) != x2:
0027         raise TestFailed("Manifest const %s lost too much precision " % x_str)
0028 
0029 check_ok(PI, PI_str)
0030 check_ok(TWOPI, TWOPI_str)
0031 

Generated by PyXR 0.9.4
SourceForge.net Logo