https://github.com/python/cpython/commit/76fea5596c235a7853cda8df87c3998d506e950c
commit: 76fea5596c235a7853cda8df87c3998d506e950c
branch: main
author: Stefano Rivera <[email protected]>
committer: vstinner <[email protected]>
date: 2025-10-22T18:36:12+02:00
summary:

gh-130317: Fix SNaN broken tests on HP PA RISC (#140452)

While looking at #140028, I found some unrelated test regressions in the
3.14 cycle. These seem to all come from #130317. From what I can tell,
that made Python more correct than it was before. According to [0], HP PA
RISC uses 1 for SNaN and thus a 0 for QNaN.

[0]: https://grouper.ieee.org/groups/1788/email/msg03272.html

files:
M Lib/test/test_capi/test_float.py
M Lib/test/test_struct.py

diff --git a/Lib/test/test_capi/test_float.py b/Lib/test/test_capi/test_float.py
index f7efe0d02549a3..983b991b4f163d 100644
--- a/Lib/test/test_capi/test_float.py
+++ b/Lib/test/test_capi/test_float.py
@@ -1,5 +1,6 @@
 import math
 import random
+import platform
 import sys
 import unittest
 import warnings
@@ -197,6 +198,10 @@ def test_pack_unpack_roundtrip_for_nans(self):
                     # PyFloat_Pack/Unpack*() API.  See also gh-130317 and
                     # e.g. https://developercommunity.visualstudio.com/t/155064
                     signaling = 0
+                    if platform.machine().startswith('parisc'):
+                        # HP PA RISC uses 0 for quiet, see:
+                        # https://en.wikipedia.org/wiki/NaN#Encoding
+                        signaling = 1
                 quiet = int(not signaling)
                 if size == 8:
                     payload = random.randint(signaling, 0x7ffffffffffff)
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 7df01f28f09118..75c76a36ee92f5 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -5,6 +5,7 @@
 import math
 import operator
 import unittest
+import platform
 import struct
 import sys
 import weakref
@@ -917,10 +918,17 @@ def test_half_float(self):
 
         # Check that packing produces a bit pattern representing a quiet NaN:
         # all exponent bits and the msb of the fraction should all be 1.
+        if platform.machine().startswith('parisc'):
+            # HP PA RISC uses 0 for quiet, see:
+            # https://en.wikipedia.org/wiki/NaN#Encoding
+            expected = 0x7c
+        else:
+            expected = 0x7e
+
         packed = struct.pack('<e', math.nan)
-        self.assertEqual(packed[1] & 0x7e, 0x7e)
+        self.assertEqual(packed[1] & 0x7e, expected)
         packed = struct.pack('<e', -math.nan)
-        self.assertEqual(packed[1] & 0x7e, 0x7e)
+        self.assertEqual(packed[1] & 0x7e, expected)
 
         # Checks for round-to-even behavior
         format_bits_float__rounding_list = [

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to