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+
13import numpy as np
24import pytest
35
@@ -12,3 +14,18 @@ def legacy_printoptions():
1214
1315 if Version (np .__version__ ) >= Version ('1.22' ):
1416 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():
172172 assert floor_exact (test_val , np .float64 ) == 2 ** (e + 1 ) - int (gap )
173173
174174
175- def test_floor_exact ():
175+ def test_floor_exact (max_digits ):
176+ max_digits (4950 ) # max longdouble is ~10**4932
177+
176178 to_test = IEEE_floats + [float ]
177179 try :
178180 type_info (np .longdouble )['nmant' ]
@@ -188,11 +190,11 @@ def test_floor_exact():
188190 for t in to_test :
189191 # A number bigger than the range returns the max
190192 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
193195 # 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
196198 # Check around end of integer precision
197199 nmant = info ['nmant' ]
198200 for i in range (nmant + 1 ):
You can’t perform that action at this time.
0 commit comments