File tree Expand file tree Collapse file tree 4 files changed +9
-13
lines changed
Expand file tree Collapse file tree 4 files changed +9
-13
lines changed Original file line number Diff line number Diff line change 11import math
22import random
3- import platform
43import sys
54import unittest
65import 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 )
Original file line number Diff line number Diff line change 2222INF = float ('inf' )
2323NAN = float ('nan' )
2424
25- _testcapi = import_helper .import_module ('_testcapi' )
26-
2725def 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
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments