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