Skip to content

Commit 77ea78c

Browse files
committed
NF: function to say if we have IEEE binary128
Function to tell us if the system has IEEE binary128 as the numpy longdouble.
1 parent f4533a4 commit 77ea78c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

nibabel/casting.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,13 @@ def best_float():
639639
return np.float64
640640

641641

642+
def have_binary128():
643+
""" True if we have a binary128 IEEE longdouble
644+
"""
645+
ti = type_info(np.longdouble)
646+
return (ti['nmant'], ti['maxexp']) == (112, 16384)
647+
648+
642649
def ok_floats():
643650
""" Return floating point types sorted by precision
644651

nibabel/tests/test_floating.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from ..casting import (floor_exact, ceil_exact, as_int, FloatingError,
66
int_to_float, floor_log2, type_info, _check_nmant,
7-
_check_maxexp, ok_floats, on_powerpc)
7+
_check_maxexp, ok_floats, on_powerpc, have_binary128)
88

99
from nose import SkipTest
1010
from nose.tools import assert_equal, assert_raises, assert_true, assert_false
@@ -258,3 +258,12 @@ def test_floor_exact():
258258
assert_equal(int_flex(-iv-gap-j, t), -iv-2*gap)
259259
assert_equal(int_ceex(-iv-j, t), -iv)
260260
assert_equal(int_ceex(-iv-gap-j, t), -iv-gap)
261+
262+
263+
def test_usable_binary128():
264+
# Check for usable binary128
265+
yes = have_binary128()
266+
abf = np.longdouble(2) ** 16383
267+
assert_equal(yes,
268+
abf.dtype.itemsize == 16 and
269+
np.isfinite(abf))

0 commit comments

Comments
 (0)