Skip to content

Commit 853e5d9

Browse files
[3.14] pythongh-130317: Fix SNaN broken tests on HP PA RISC (pythonGH-140452) (python#140467)
pythongh-130317: Fix SNaN broken tests on HP PA RISC (pythonGH-140452) While looking at pythonGH-140028, I found some unrelated test regressions in the 3.14 cycle. These seem to all come from pythonGH-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 (cherry picked from commit 76fea55) Co-authored-by: Stefano Rivera <[email protected]>
1 parent 01b52ea commit 853e5d9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Lib/test/test_capi/test_float.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
import random
3+
import platform
34
import sys
45
import unittest
56
import warnings
@@ -197,6 +198,10 @@ def test_pack_unpack_roundtrip_for_nans(self):
197198
# PyFloat_Pack/Unpack*() API. See also gh-130317 and
198199
# e.g. https://developercommunity.visualstudio.com/t/155064
199200
signaling = 0
201+
if platform.machine().startswith('parisc'):
202+
# HP PA RISC uses 0 for quiet, see:
203+
# https://en.wikipedia.org/wiki/NaN#Encoding
204+
signaling = 1
200205
quiet = int(not signaling)
201206
if size == 8:
202207
payload = random.randint(signaling, 0x7ffffffffffff)

Lib/test/test_struct.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import math
66
import operator
77
import unittest
8+
import platform
89
import struct
910
import sys
1011
import weakref
@@ -917,10 +918,17 @@ def test_half_float(self):
917918

918919
# Check that packing produces a bit pattern representing a quiet NaN:
919920
# all exponent bits and the msb of the fraction should all be 1.
921+
if platform.machine().startswith('parisc'):
922+
# HP PA RISC uses 0 for quiet, see:
923+
# https://en.wikipedia.org/wiki/NaN#Encoding
924+
expected = 0x7c
925+
else:
926+
expected = 0x7e
927+
920928
packed = struct.pack('<e', math.nan)
921-
self.assertEqual(packed[1] & 0x7e, 0x7e)
929+
self.assertEqual(packed[1] & 0x7e, expected)
922930
packed = struct.pack('<e', -math.nan)
923-
self.assertEqual(packed[1] & 0x7e, 0x7e)
931+
self.assertEqual(packed[1] & 0x7e, expected)
924932

925933
# Checks for round-to-even behavior
926934
format_bits_float__rounding_list = [

0 commit comments

Comments
 (0)