Skip to content

Commit 376c04d

Browse files
committed
Move nan flag to Modules/_testcapi/float.c and use bool
... and migrate another parisc detection to the new nan flag
1 parent 13ab453 commit 376c04d

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

Lib/test/test_capi/test_float.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import math
22
import random
3-
import platform
43
import sys
54
import unittest
65
import warnings
@@ -215,8 +214,8 @@ def test_pack_unpack_roundtrip_for_nans(self):
215214
# PyFloat_Pack/Unpack*() API. See also gh-130317 and
216215
# e.g. https://developercommunity.visualstudio.com/t/155064
217216
signaling = 0
218-
if platform.machine().startswith('parisc'):
219-
# HP PA RISC uses 0 for quiet, see:
217+
if _testcapi.nan_msb_is_signaling:
218+
# HP PA RISC and some MIPS CPUs use 0 for quiet, see:
220219
# https://en.wikipedia.org/wiki/NaN#Encoding
221220
signaling = 1
222221
i = make_nan(size, sign, not signaling)

Lib/test/test_struct.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
INF = float('inf')
2323
NAN = float('nan')
2424

25-
_testcapi = import_helper.import_module('_testcapi')
26-
2725
def iter_integer_formats(byteorders=byteorders):
2826
for code in integer_codes:
2927
for byteorder in byteorders:
@@ -892,6 +890,7 @@ def test_module_func(self):
892890
self.assertRaises(StopIteration, next, it)
893891

894892
def test_half_float(self):
893+
_testcapi = import_helper.import_module('_testcapi')
895894
# Little-endian examples from:
896895
# http://en.wikipedia.org/wiki/Half_precision_floating-point_format
897896
format_bits_float__cleanRoundtrip_list = [
@@ -936,7 +935,7 @@ def test_half_float(self):
936935

937936
# Check that packing produces a bit pattern representing a quiet NaN:
938937
# all exponent bits and the msb of the fraction should all be 1.
939-
if _testcapi.nan_encoding == 'parisc':
938+
if _testcapi.nan_msb_is_signaling:
940939
# HP PA RISC and some MIPS CPUs use 0 for quiet, see:
941940
# https://en.wikipedia.org/wiki/NaN#Encoding
942941
expected = 0x7c

Modules/_testcapi/float.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,9 @@ _PyTestCapi_Init_Float(PyObject *mod)
171171
return -1;
172172
}
173173

174-
return 0;
174+
#if (defined(__mips__) && !defined(__mips_nan2008)) || defined(__hppa__)
175+
return PyModule_Add(mod, "nan_msb_is_signaling", PyBool_FromLong(1));
176+
#else
177+
return PyModule_Add(mod, "nan_msb_is_signaling", PyBool_FromLong(0));
178+
#endif
175179
}

Modules/_testcapimodule.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3359,12 +3359,6 @@ _testcapi_exec(PyObject *m)
33593359
PyModule_AddObject(m, "INT64_MAX", PyLong_FromInt64(INT64_MAX));
33603360
PyModule_AddObject(m, "UINT64_MAX", PyLong_FromUInt64(UINT64_MAX));
33613361

3362-
#if (defined(__mips__) && !defined(__mips_nan2008)) || defined(__hppa__)
3363-
PyModule_Add(m, "nan_encoding", PyUnicode_FromString("parisc"));
3364-
#else
3365-
PyModule_Add(m, "nan_encoding", PyUnicode_FromString("regular"));
3366-
#endif
3367-
33683362
if (PyModule_AddIntMacro(m, _Py_STACK_GROWS_DOWN)) {
33693363
return -1;
33703364
}

0 commit comments

Comments
 (0)