Skip to content

Commit f4533a4

Browse files
committed
BF: add check for powerpc platform and longdouble
Catch double pair on IBM PPC as well as Mac PPC
1 parent 143c16c commit f4533a4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

nibabel/casting.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ class FloatingError(Exception):
168168
pass
169169

170170

171+
def on_powerpc():
172+
""" True if we are running on a Power PC platform
173+
174+
Has to deal with older Macs and IBM POWER7 series among others
175+
"""
176+
return processor() == 'powerpc' or machine().startswith('ppc')
177+
178+
171179
def type_info(np_type):
172180
""" Return dict with min, max, nexp, nmant, width for numpy type `np_type`
173181
@@ -249,10 +257,10 @@ def type_info(np_type):
249257
# complex equivalent.
250258
if not np_type in (np.longdouble, np.longcomplex) or width not in (16, 32):
251259
raise FloatingError('We had not expected type %s' % np_type)
252-
if (vals == (1, 1, 16) and processor() == 'powerpc' and
260+
if (vals == (1, 1, 16) and on_powerpc() and
253261
_check_maxexp(np.longdouble, 1024)):
254262
# double pair on PPC. The _check_nmant routine does not work for this
255-
# type, hence the processor check
263+
# type, hence the powerpc platform check instead
256264
ret.update(dict(nmant = 106, width=width))
257265
elif (_check_nmant(np.longdouble, 52) and
258266
_check_maxexp(np.longdouble, 11)):

nibabel/tests/test_floating.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
""" Test floating point deconstructions and floor methods
22
"""
3-
from platform import processor
4-
53
import numpy as np
64

75
from ..casting import (floor_exact, ceil_exact, as_int, FloatingError,
86
int_to_float, floor_log2, type_info, _check_nmant,
9-
_check_maxexp, ok_floats)
7+
_check_maxexp, ok_floats, on_powerpc)
108

119
from nose import SkipTest
1210
from nose.tools import assert_equal, assert_raises, assert_true, assert_false
@@ -234,7 +232,7 @@ def test_floor_exact():
234232
assert_equal(func(-iv+1, t), -iv+1)
235233
# The nmant value for longdouble on PPC appears to be conservative, so
236234
# that the tests for behavior above the nmant range fail
237-
if t is np.longdouble and processor() == 'powerpc':
235+
if t is np.longdouble and on_powerpc():
238236
continue
239237
# Confirm to ourselves that 2**(nmant+1) can't be exactly represented
240238
iv = 2**(nmant+1)

0 commit comments

Comments
 (0)