Skip to content

Commit f30b8c0

Browse files
committed
RF - replace flt2nmant with type_info
Use type_info nmant estimate.
1 parent d919a3d commit f30b8c0

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

nibabel/casting.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -249,26 +249,7 @@ def flt2nmant(flt_type):
249249
return _flt_nmant[flt_type]
250250
except KeyError:
251251
pass
252-
fi = np.finfo(flt_type)
253-
nmant, nexp = fi.nmant, fi.nexp
254-
# Assuming the np.float type is always IEEE 64 bit
255-
if flt_type is np.float and (nmant, nexp) == (52, 11):
256-
return 52
257-
# Now we should be testing long doubles
258-
assert flt_type is np.longdouble
259-
if (nmant, nexp) == (63, 15): # 80-bit intel type
260-
return 63 # Not including explicit first digit
261-
# We test the declared nmant by stepping up and down. These tests assume a
262-
# binary format
263-
i_end_contig = 2**(nmant+1) # int
264-
f_end_contig = flt_type(i_end_contig)
265-
# We need as_int here because long doubles do not necessarily convert
266-
# correctly to ints with int() - see
267-
# http://projects.scipy.org/numpy/ticket/1395
268-
if as_int(f_end_contig-1) == (i_end_contig-1): # still representable
269-
if as_int(f_end_contig+1) == i_end_contig: # Rounding down
270-
return nmant
271-
raise FloatingError('Cannot be confident of nmant value for %s' % flt_type)
252+
return type_info(flt_type)['nmant']
272253

273254

274255
def as_int(x, check=True):

0 commit comments

Comments
 (0)