File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change
1
+ import sys
2
+
1
3
import numpy as np
2
4
import pytest
3
5
@@ -12,3 +14,18 @@ def legacy_printoptions():
12
14
13
15
if Version (np .__version__ ) >= Version ('1.22' ):
14
16
np .set_printoptions (legacy = '1.21' )
17
+
18
+
19
+ @pytest .fixture
20
+ def max_digits ():
21
+ # Set maximum number of digits for int/str conversion for
22
+ # duration of a test
23
+ try :
24
+ orig_max_str_digits = sys .get_int_max_str_digits ()
25
+ yield sys .set_int_max_str_digits
26
+ sys .set_int_max_str_digits (orig_max_str_digits )
27
+ except AttributeError :
28
+ # Nothing to do for versions of Python that lack these methods
29
+ # They were added as DoS protection in Python 3.11 and backported to
30
+ # some other versions.
31
+ yield lambda x : None
Original file line number Diff line number Diff line change @@ -172,7 +172,9 @@ def test_floor_exact_64():
172
172
assert floor_exact (test_val , np .float64 ) == 2 ** (e + 1 ) - int (gap )
173
173
174
174
175
- def test_floor_exact ():
175
+ def test_floor_exact (max_digits ):
176
+ max_digits (4950 ) # max longdouble is ~10**4932
177
+
176
178
to_test = IEEE_floats + [float ]
177
179
try :
178
180
type_info (np .longdouble )['nmant' ]
@@ -188,11 +190,11 @@ def test_floor_exact():
188
190
for t in to_test :
189
191
# A number bigger than the range returns the max
190
192
info = type_info (t )
191
- assert floor_exact (2 ** 5000 , t ) == np .inf
192
- assert ceil_exact (2 ** 5000 , t ) == np .inf
193
+ assert floor_exact (10 ** 4933 , t ) == np .inf
194
+ assert ceil_exact (10 ** 4933 , t ) == np .inf
193
195
# A number more negative returns -inf
194
- assert floor_exact (- (2 ** 5000 ), t ) == - np .inf
195
- assert ceil_exact (- (2 ** 5000 ), t ) == - np .inf
196
+ assert floor_exact (- (10 ** 4933 ), t ) == - np .inf
197
+ assert ceil_exact (- (10 ** 4933 ), t ) == - np .inf
196
198
# Check around end of integer precision
197
199
nmant = info ['nmant' ]
198
200
for i in range (nmant + 1 ):
You can’t perform that action at this time.
0 commit comments