ยปCore Development>Code coverage>Lib/test/double_const.py

Python code coverage for Lib/test/double_const.py

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