aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_capi/test_float.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_capi/test_float.py')
-rw-r--r--Lib/test/test_capi/test_float.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/Lib/test/test_capi/test_float.py b/Lib/test/test_capi/test_float.py
index 44570bf6379..f7efe0d0254 100644
--- a/Lib/test/test_capi/test_float.py
+++ b/Lib/test/test_capi/test_float.py
@@ -180,12 +180,6 @@ class CAPIFloatTest(unittest.TestCase):
self.assertEqual(value2, value)
@unittest.skipUnless(HAVE_IEEE_754, "requires IEEE 754")
- # Skip on x86 (32-bit), since these tests fail. The problem is that sNaN
- # doubles become qNaN doubles just by the C calling convention, there is no
- # way to preserve sNaN doubles between C function calls. But tests pass
- # on Windows x86.
- @unittest.skipIf((sys.maxsize == 2147483647) and not(sys.platform == 'win32'),
- 'test fails on x86 (32-bit)')
def test_pack_unpack_roundtrip_for_nans(self):
pack = _testcapi.float_pack
unpack = _testcapi.float_unpack
@@ -193,28 +187,31 @@ class CAPIFloatTest(unittest.TestCase):
for _ in range(10):
for size in (2, 4, 8):
sign = random.randint(0, 1)
- signaling = random.randint(0, 1)
+ if sys.maxsize != 2147483647: # not it 32-bit mode
+ signaling = random.randint(0, 1)
+ else:
+ # Skip sNaN's on x86 (32-bit). The problem is that sNaN
+ # doubles become qNaN doubles just by the C calling
+ # convention, there is no way to preserve sNaN doubles
+ # between C function calls with the current
+ # PyFloat_Pack/Unpack*() API. See also gh-130317 and
+ # e.g. https://developercommunity.visualstudio.com/t/155064
+ signaling = 0
quiet = int(not signaling)
if size == 8:
- payload = random.randint(signaling, 1 << 50)
+ payload = random.randint(signaling, 0x7ffffffffffff)
i = (sign << 63) + (0x7ff << 52) + (quiet << 51) + payload
elif size == 4:
- payload = random.randint(signaling, 1 << 21)
+ payload = random.randint(signaling, 0x3fffff)
i = (sign << 31) + (0xff << 23) + (quiet << 22) + payload
elif size == 2:
- payload = random.randint(signaling, 1 << 8)
+ payload = random.randint(signaling, 0x1ff)
i = (sign << 15) + (0x1f << 10) + (quiet << 9) + payload
data = bytes.fromhex(f'{i:x}')
for endian in (BIG_ENDIAN, LITTLE_ENDIAN):
with self.subTest(data=data, size=size, endian=endian):
data1 = data if endian == BIG_ENDIAN else data[::-1]
value = unpack(data1, endian)
- if signaling and sys.platform == 'win32':
- # On Windows x86, sNaN becomes qNaN when returned
- # from function. That's a known bug, e.g.
- # https://developercommunity.visualstudio.com/t/155064
- # (see also gh-130317).
- value = _testcapi.float_set_snan(value)
data2 = pack(size, value, endian)
self.assertTrue(math.isnan(value))
self.assertEqual(data1, data2)