|
15 | 15 | floor_exact,
|
16 | 16 | floor_log2,
|
17 | 17 | have_binary128,
|
18 |
| - int_to_float, |
19 | 18 | longdouble_precision_improved,
|
20 | 19 | ok_floats,
|
21 | 20 | on_powerpc,
|
@@ -127,59 +126,21 @@ def test_check_nmant_nexp():
|
127 | 126 | assert _check_maxexp(t, ti['maxexp'])
|
128 | 127 |
|
129 | 128 |
|
130 |
| -def test_int_to_float(): |
131 |
| - # Convert python integer to floating point |
132 |
| - # Standard float types just return cast value |
133 |
| - for ie3 in IEEE_floats: |
134 |
| - nmant = type_info(ie3)['nmant'] |
135 |
| - for p in range(nmant + 3): |
136 |
| - i = 2**p + 1 |
137 |
| - assert int_to_float(i, ie3) == ie3(i) |
138 |
| - assert int_to_float(-i, ie3) == ie3(-i) |
139 |
| - # IEEEs in this case are binary formats only |
140 |
| - nexp = floor_log2(type_info(ie3)['max']) |
141 |
| - # Values too large for the format |
142 |
| - smn, smx = -(2 ** (nexp + 1)), 2 ** (nexp + 1) |
143 |
| - if ie3 is np.float64: |
144 |
| - with pytest.raises(OverflowError): |
145 |
| - int_to_float(smn, ie3) |
146 |
| - with pytest.raises(OverflowError): |
147 |
| - int_to_float(smx, ie3) |
148 |
| - else: |
149 |
| - assert int_to_float(smn, ie3) == ie3(smn) |
150 |
| - assert int_to_float(smx, ie3) == ie3(smx) |
151 |
| - # Longdoubles do better than int, we hope |
152 |
| - LD = np.longdouble |
153 |
| - # up to integer precision of float64 nmant, we get the same result as for |
154 |
| - # casting directly |
| 129 | +def test_int_longdouble_np_regression(): |
| 130 | + # Test longdouble conversion from int works as expected |
| 131 | + # Previous versions of numpy would fail, and we used a custom int_to_float() |
| 132 | + # function. This test remains to ensure we don't need to bring it back. |
155 | 133 | nmant = type_info(np.float64)['nmant']
|
156 |
| - for p in range(nmant + 2): # implicit |
157 |
| - i = 2**p - 1 |
158 |
| - assert int_to_float(i, LD) == LD(i) |
159 |
| - assert int_to_float(-i, LD) == LD(-i) |
160 |
| - # Above max of float64, we're hosed |
161 |
| - nexp64 = floor_log2(type_info(np.float64)['max']) |
162 |
| - smn64, smx64 = -(2 ** (nexp64 + 1)), 2 ** (nexp64 + 1) |
163 |
| - # The algorithm here implemented goes through float64, so supermax and |
164 |
| - # supermin will cause overflow errors |
165 |
| - with pytest.raises(OverflowError): |
166 |
| - int_to_float(smn64, LD) |
167 |
| - with pytest.raises(OverflowError): |
168 |
| - int_to_float(smx64, LD) |
169 |
| - try: |
170 |
| - nmant = type_info(np.longdouble)['nmant'] |
171 |
| - except FloatingError: # don't know where to test |
172 |
| - return |
173 | 134 | # test we recover precision just above nmant
|
174 | 135 | i = 2 ** (nmant + 1) - 1
|
175 |
| - assert int(int_to_float(i, LD)) == i |
176 |
| - assert int(int_to_float(-i, LD)) == -i |
| 136 | + assert int(np.longdouble(i)) == i |
| 137 | + assert int(np.longdouble(-i)) == -i |
177 | 138 | # If longdouble can cope with 2**64, test
|
178 | 139 | if nmant >= 63:
|
179 | 140 | # Check conversion to int; the line below causes an error subtracting
|
180 | 141 | # ints / uint64 values, at least for Python 3.3 and numpy dev 1.8
|
181 | 142 | big_int = np.uint64(2**64 - 1)
|
182 |
| - assert int(int_to_float(big_int, LD)) == big_int |
| 143 | + assert int(np.longdouble(big_int)) == big_int |
183 | 144 |
|
184 | 145 |
|
185 | 146 | def test_int_np_regression():
|
|
0 commit comments