1 | n/a | from test.support import TestFailed |
---|
2 | n/a | |
---|
3 | n/a | # A test for SF bug 422177: manifest float constants varied way too much in |
---|
4 | n/a | # precision depending on whether Python was loading a module for the first |
---|
5 | n/a | # time, or reloading it from a precompiled .pyc. The "expected" failure |
---|
6 | n/a | # mode is that when test_import imports this after all .pyc files have been |
---|
7 | n/a | # erased, it passes, but when test_import imports this from |
---|
8 | n/a | # double_const.pyc, it fails. This indicates a woeful loss of precision in |
---|
9 | n/a | # the marshal format for doubles. It's also possible that repr() doesn't |
---|
10 | n/a | # produce enough digits to get reasonable precision for this box. |
---|
11 | n/a | |
---|
12 | n/a | PI = 3.14159265358979324 |
---|
13 | n/a | TWOPI = 6.28318530717958648 |
---|
14 | n/a | |
---|
15 | n/a | PI_str = "3.14159265358979324" |
---|
16 | n/a | TWOPI_str = "6.28318530717958648" |
---|
17 | n/a | |
---|
18 | n/a | # Verify that the double x is within a few bits of eval(x_str). |
---|
19 | n/a | def check_ok(x, x_str): |
---|
20 | n/a | assert x > 0.0 |
---|
21 | n/a | x2 = eval(x_str) |
---|
22 | n/a | assert x2 > 0.0 |
---|
23 | n/a | diff = abs(x - x2) |
---|
24 | n/a | # If diff is no larger than 3 ULP (wrt x2), then diff/8 is no larger |
---|
25 | n/a | # than 0.375 ULP, so adding diff/8 to x2 should have no effect. |
---|
26 | n/a | if x2 + (diff / 8.) != x2: |
---|
27 | n/a | raise TestFailed("Manifest const %s lost too much precision " % x_str) |
---|
28 | n/a | |
---|
29 | n/a | check_ok(PI, PI_str) |
---|
30 | n/a | check_ok(TWOPI, TWOPI_str) |
---|