2
2
"""
3
3
import numpy as np
4
4
5
- from ..casting import (floor_exact , flt2nmant , as_int , FloatingError ,
6
- int_to_float , floor_log2 , type_info )
5
+ from ..casting import (floor_exact , as_int , FloatingError , int_to_float ,
6
+ floor_log2 , type_info )
7
7
8
8
from nose import SkipTest
9
9
from nose .tools import assert_equal , assert_raises
@@ -60,11 +60,11 @@ def test_type_info():
60
60
infod )
61
61
62
62
63
- def test_flt2nmant ():
63
+ def test_nmant ():
64
64
for t in IEEE_floats :
65
- assert_equal (flt2nmant (t ), np .finfo (t ).nmant )
65
+ assert_equal (type_info (t )[ 'nmant' ] , np .finfo (t ).nmant )
66
66
if (LD_INFO .nmant , LD_INFO .nexp ) == (63 , 15 ):
67
- assert_equal (flt2nmant (np .longdouble ), 63 )
67
+ assert_equal (type_info (np .longdouble )[ 'nmant' ] , 63 )
68
68
69
69
70
70
def test_as_int ():
@@ -81,7 +81,7 @@ def test_as_int():
81
81
# longdouble appears to have 52 bit precision, but we avoid that by checking
82
82
# for known precisions that are less than that required
83
83
try :
84
- nmant = flt2nmant (np .longdouble )
84
+ nmant = type_info (np .longdouble )[ 'nmant' ]
85
85
except FloatingError :
86
86
nmant = 63 # Unknown precision, let's hope it's at least 63
87
87
v = np .longdouble (2 ) ** (nmant + 1 ) - 1
@@ -97,7 +97,7 @@ def test_int_to_float():
97
97
# Concert python integer to floating point
98
98
# Standard float types just return cast value
99
99
for ie3 in IEEE_floats :
100
- nmant = flt2nmant (ie3 )
100
+ nmant = type_info (ie3 )[ 'nmant' ]
101
101
for p in range (nmant + 3 ):
102
102
i = 2 ** p + 1
103
103
assert_equal (int_to_float (i , ie3 ), ie3 (i ))
@@ -116,7 +116,8 @@ def test_int_to_float():
116
116
LD = np .longdouble
117
117
# up to integer precision of float64 nmant, we get the same result as for
118
118
# casting directly
119
- for p in range (flt2nmant (np .float64 )+ 2 ): # implicit
119
+ nmant = type_info (np .float64 )['nmant' ]
120
+ for p in range (nmant + 2 ): # implicit
120
121
i = 2 ** p - 1
121
122
assert_equal (int_to_float (i , LD ), LD (i ))
122
123
assert_equal (int_to_float (- i , LD ), LD (- i ))
@@ -128,7 +129,7 @@ def test_int_to_float():
128
129
assert_raises (OverflowError , int_to_float , smn64 , LD )
129
130
assert_raises (OverflowError , int_to_float , smx64 , LD )
130
131
try :
131
- nmant = flt2nmant (np .longdouble )
132
+ nmant = type_info (np .longdouble )[ 'nmant' ]
132
133
except FloatingError : # don't know where to test
133
134
return
134
135
# Assuming nmant is greater than that for float64, test we recover precision
@@ -169,7 +170,7 @@ def test_floor_exact_64():
169
170
def test_floor_exact ():
170
171
to_test = IEEE_floats + [float ]
171
172
try :
172
- flt2nmant (np .longdouble )
173
+ type_info (np .longdouble )[ 'nmant' ]
173
174
except FloatingError :
174
175
# Significand bit count not reliable, don't test long double
175
176
pass
@@ -181,7 +182,7 @@ def test_floor_exact():
181
182
for t in to_test :
182
183
# A number bigger than the range returns the max
183
184
assert_equal (floor_exact (2 ** 5000 , t ), np .finfo (t ).max )
184
- nmant = flt2nmant (t )
185
+ nmant = type_info (t )[ 'nmant' ]
185
186
for i in range (nmant + 1 ):
186
187
iv = 2 ** i
187
188
# up to 2**nmant should be exactly representable
0 commit comments