Skip to content

Commit 88ffe0d

Browse files
committed
tests/string_format_modulo2: Split off intbig test.
1 parent 320099a commit 88ffe0d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

tests/float/string_format_modulo2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test(num, num_str):
1818
# check pure zero
1919
test(0.0, '0.0')
2020

21-
# check most powers of 10, making sure to include exponents with 3 digits
22-
for e in range(-101, 102):
21+
# check some powers of 10, making sure to include exponents with 3 digits
22+
for e in range(-8, 8):
2323
num = pow(10, e)
2424
test(num, '1e%d' % e)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# test formatting floats with large precision, that it doesn't overflow the buffer
2+
3+
def test(num, num_str):
4+
if num == float('inf') or num == 0.0 and num_str != '0.0':
5+
# skip numbers that overflow or underflow the FP precision
6+
return
7+
for kind in ('e', 'f', 'g'):
8+
# check precision either side of the size of the buffer (32 bytes)
9+
for prec in range(23, 36, 2):
10+
fmt = '%.' + '%d' % prec + kind
11+
s = fmt % num
12+
check = abs(float(s) - num)
13+
if num > 1:
14+
check /= num
15+
if check > 1e-6:
16+
print('FAIL', num_str, fmt, s, len(s), check)
17+
18+
# check most powers of 10, making sure to include exponents with 3 digits
19+
for e in range(-101, 102):
20+
num = pow(10, e)
21+
test(num, '1e%d' % e)

0 commit comments

Comments
 (0)