summaryrefslogtreecommitdiff
path: root/numpy/core/getlimits.py
diff options
context:
space:
mode:
authorAndrew Nelson <andyfaff@gmail.com>2023-01-23 13:24:06 +1100
committerAndrew Nelson <andyfaff@gmail.com>2023-02-01 18:43:05 +1100
commit20d397400d6325cff3decbba3d6195418e873237 (patch)
treee70f11ab48842fb22a669bed7cfc50411f554daf /numpy/core/getlimits.py
parent3d21a27db036f408ea4d21ac011ac082b49b4aeb (diff)
downloadnumpy-20d397400d6325cff3decbba3d6195418e873237.tar.gz
WHL: musllinux wheels [wheel build]
Diffstat (limited to 'numpy/core/getlimits.py')
-rw-r--r--numpy/core/getlimits.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/numpy/core/getlimits.py b/numpy/core/getlimits.py
index 8146c4644..f848af085 100644
--- a/numpy/core/getlimits.py
+++ b/numpy/core/getlimits.py
@@ -147,8 +147,12 @@ _MACHAR_PARAMS = {
# Key to identify the floating point type. Key is result of
# ftype('-0.1').newbyteorder('<').tobytes()
+#
+# 20230201 - use (ftype(-1.0) / ftype(10.0)).newbyteorder('<').tobytes()
+# instead because stold may have deficiencies on some platforms.
# See:
# https://perl5.git.perl.org/perl.git/blob/3118d7d684b56cbeb702af874f4326683c45f045:/Configure
+
_KNOWN_TYPES = {}
def _register_type(machar, bytepat):
_KNOWN_TYPES[bytepat] = machar
@@ -240,8 +244,6 @@ def _register_known_types():
# IEEE 754 128-bit binary float
_register_type(float128_ma,
b'\x9a\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\xfb\xbf')
- _register_type(float128_ma,
- b'\x9a\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\xfb\xbf')
_float_ma[128] = float128_ma
# Known parameters for float80 (Intel 80-bit extended precision)
@@ -329,7 +331,9 @@ def _get_machar(ftype):
if params is None:
raise ValueError(repr(ftype))
# Detect known / suspected types
- key = ftype('-0.1').newbyteorder('<').tobytes()
+ # ftype(-1.0) / ftype(10.0) is better than ftype('-0.1') because stold
+ # may be deficient
+ key = (ftype(-1.0) / ftype(10.)).newbyteorder('<').tobytes()
ma_like = None
if ftype == ntypes.longdouble:
# Could be 80 bit == 10 byte extended precision, where last bytes can
@@ -338,7 +342,14 @@ def _get_machar(ftype):
# random garbage.
ma_like = _KNOWN_TYPES.get(key[:10])
if ma_like is None:
+ # see if the full key is known.
ma_like = _KNOWN_TYPES.get(key)
+ if ma_like is None and len(key) == 16:
+ # machine limits could be f80 masquerading as np.float128,
+ # find all keys with length 16 and make new dict, but make the keys
+ # only 10 bytes long, the last bytes can be random garbage
+ _kt = {k[:10]: v for k, v in _KNOWN_TYPES.items() if len(k) == 16}
+ ma_like = _kt.get(key[:10])
if ma_like is not None:
return ma_like
# Fall back to parameter discovery