Skip to content

Commit 6dad088

Browse files
committed
tests/float: Adjust float-parsing tests to pass with only a small error.
Float parsing (both single and double precision) may have a relative error of order the floating point precision, so adjust tests to take this into account by not printing all of the digits of the answer.
1 parent 4c2230a commit 6dad088

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

tests/float/float_parse.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
print(float('1.015625') - float('1015625e-6'))
88

99
# very large integer part with a very negative exponent should cancel out
10-
print(float('9' * 60 + 'e-60'))
11-
print(float('9' * 60 + 'e-40'))
12-
print(float('9' * 60 + 'e-20') == float('1e40'))
10+
print('%.4e' % float('9' * 60 + 'e-60'))
11+
print('%.4e' % float('9' * 60 + 'e-40'))
1312

1413
# many fractional digits
1514
print(float('.' + '9' * 70))

tests/float/float_parse_doubleprec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
print(float('.' + '9' * 400 + 'e-100'))
1212

1313
# tiny fraction with large exponent
14-
print(float('.' + '0' * 400 + '9e100'))
15-
print(float('.' + '0' * 400 + '9e200'))
16-
print(float('.' + '0' * 400 + '9e400'))
14+
print('%.14e' % float('.' + '0' * 400 + '9e100'))
15+
print('%.14e' % float('.' + '0' * 400 + '9e200'))
16+
print('%.14e' % float('.' + '0' * 400 + '9e400'))
1717

1818
# ensure that accuracy is retained when value is close to a subnormal
1919
print(float('1.00000000000000000000e-307'))

0 commit comments

Comments
 (0)