From 514d738d9eb21c611390fd415bf4e87f3a7a8696 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 22 May 2026 09:25:51 +0300 Subject: [PATCH] gh-85989: add HAVE_DOUBLE_ROUNDING check to test.support --- Lib/test/support/__init__.py | 6 ++++++ Lib/test/test_builtin.py | 7 +------ Lib/test/test_math.py | 7 +------ Lib/test/test_statistics.py | 8 +------- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 2cac70f4ab2afb..0348074ba6c8c6 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -73,6 +73,7 @@ "run_no_yield_async_fn", "run_yielding_async_fn", "async_yield", "reset_code", "on_github_actions", "requires_root_user", "requires_non_root_user", + "HAVE_DOUBLE_ROUNDING", ] @@ -524,6 +525,11 @@ def dec(*args, **kwargs): float.__getformat__("double").startswith("IEEE"), "test requires IEEE 754 doubles") +# detect evidence of double-rounding: fsum is not always correctly +# rounded on machines that suffer from double rounding. +x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer +HAVE_DOUBLE_ROUNDING = (x + y == 1e16 + 4) + def requires_zlib(reason='requires zlib'): try: import zlib diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 1f52b16948c703..a3566eb38b3063 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -39,7 +39,7 @@ from test.support.script_helper import assert_python_ok from test.support.testcase import ComplexesAreIdenticalMixin from test.support.warnings_helper import check_warnings -from test.support import requires_IEEE_754 +from test.support import HAVE_DOUBLE_ROUNDING, requires_IEEE_754 from unittest.mock import MagicMock, patch try: import pty, signal @@ -47,11 +47,6 @@ pty = signal = None -# Detect evidence of double-rounding: sum() does not always -# get improved accuracy on machines that suffer from double rounding. -x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer -HAVE_DOUBLE_ROUNDING = (x + y == 1e16 + 4) - # used as proof of globals being used A_GLOBAL_VALUE = 123 A_SENTINEL = sentinel("A_SENTINEL") diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 8f9a239bead130..dd142aeb0cb888 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -1,7 +1,7 @@ # Python test set -- math module # XXXX Should not do tests around zero only -from test.support import verbose, requires_IEEE_754 +from test.support import HAVE_DOUBLE_ROUNDING, verbose, requires_IEEE_754 from test import support import unittest import fractions @@ -23,11 +23,6 @@ FLOAT_MAX = sys.float_info.max FLOAT_MIN = sys.float_info.min -# detect evidence of double-rounding: fsum is not always correctly -# rounded on machines that suffer from double rounding. -x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer -HAVE_DOUBLE_ROUNDING = (x + y == 1e16 + 4) - # locate file with test values if __name__ == '__main__': file = sys.argv[0] diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py index 677a87b51b9192..18ac5b17b9b481 100644 --- a/Lib/test/test_statistics.py +++ b/Lib/test/test_statistics.py @@ -16,7 +16,7 @@ import sys import unittest from test import support -from test.support import import_helper, requires_IEEE_754 +from test.support import HAVE_DOUBLE_ROUNDING, import_helper, requires_IEEE_754 from decimal import Decimal from fractions import Fraction @@ -28,12 +28,6 @@ # === Helper functions and class === -# Test copied from Lib/test/test_math.py -# detect evidence of double-rounding: fsum is not always correctly -# rounded on machines that suffer from double rounding. -x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer -HAVE_DOUBLE_ROUNDING = (x + y == 1e16 + 4) - def sign(x): """Return -1.0 for negatives, including -0.0, otherwise +1.0.""" return math.copysign(1, x)