Skip to content

Commit 160b5d5

Browse files
committed
BF - type info for odd float96 on windows
Float96 on windows appears to be a float64 padded to 96 bits, and with an incorrect finfo nexp value of 15.
1 parent 9637ed8 commit 160b5d5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

nibabel/casting.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,29 @@ def type_info(np_type):
207207
if np_type in (_float16, np.float32, np.float64,
208208
np.complex64, np.complex128):
209209
return ret
210+
info_64 = np.finfo(np.float64)
210211
if dt.kind == 'c':
211212
assert np_type is np.longcomplex
212213
vals = (nmant, nexp, width / 2)
213214
else:
214215
assert np_type is np.longdouble
215216
vals = (nmant, nexp, width)
216217
if vals in ((112, 15, 16), # binary128
218+
(info_64.nmant, info_64.nexp, 8), # float64
217219
(63, 15, 12), (63, 15, 16)): # Intel extended 80
218220
pass # these are OK
221+
elif vals in ((52, 15, 12), # windows float96
222+
(52, 15, 16)): # windows float128?
223+
# On windows 32 bit at least, float96 appears to be a float64 padded to
224+
# 96 bits. The nexp == 15 is the same as for intel 80 but nexp in fact
225+
# appears to be 11 as for float64
226+
return dict(min=np_type(info_64.min), max=np_type(info_64.max),
227+
nmant=info_64.nmant, nexp=info_64.nexp, width=width)
219228
elif vals == (1, 1, 16) and processor() == 'powerpc': # broken PPC
220-
dbl_info = np.finfo(np.float64)
221-
return dict(min=np_type(dbl_info.min), max=np_type(dbl_info.max),
229+
return dict(min=np_type(info_64.min), max=np_type(info_64.max),
222230
nmant=106, nexp=11, width=width)
223231
else: # don't recognize the type
224-
raise FloatingError('We had not expected this type')
232+
raise FloatingError('We had not expected type %s' % np_type)
225233
return ret
226234

227235

0 commit comments

Comments
 (0)