diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-09-06 23:00:21 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-09-06 23:00:21 (GMT) |
commit | c5b235c59c956ec972521ac0b0e5dc3aa56ca19a (patch) | |
tree | 646d364591c3ef6e00f1d795571ebd7da96320f1 /Lib/test/test_complex.py | |
parent | 419670dc6017b5b463c88b08b4855aa7c9d396a3 (diff) | |
download | cpython-c5b235c59c956ec972521ac0b0e5dc3aa56ca19a.zip cpython-c5b235c59c956ec972521ac0b0e5dc3aa56ca19a.tar.gz cpython-c5b235c59c956ec972521ac0b0e5dc3aa56ca19a.tar.bz2 |
Reverting to rev 1.2. Apparently gcc doesn't use the extended-precision
capabilities of the Pentium FPU, so what should have been (and were on
Windows) exact results got fuzzy. Then it turns out test_support.fcmp()
isn't tolerant of tiny errors when *one* of the comparands is 0, but
test_complex's old check_close_real() is. Rather than fix gcc <wink>,
easier to revert this test and revisit after the release.
Diffstat (limited to 'Lib/test/test_complex.py')
-rw-r--r-- | Lib/test/test_complex.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index 0e268ab..9faab71 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -1,13 +1,26 @@ -from test_support import TestFailed, fcmp +from test_support import TestFailed from random import random # XXX need many, many more tests here. nerrors = 0 -def check_close(x, y): +def check_close_real(x, y, eps=1e-9): + """Return true iff floats x and y "are close\"""" + # put the one with larger magnitude second + if abs(x) > abs(y): + x, y = y, x + if y == 0: + return abs(x) < eps + if x == 0: + return abs(y) < eps + # check that relative difference < eps + return abs((x-y)/y) < eps + +def check_close(x, y, eps=1e-9): """Return true iff complexes x and y "are close\"""" - return fcmp(x.real, y.real) == 0 == fcmp(x.imag, y.imag) + return check_close_real(x.real, y.real, eps) and \ + check_close_real(x.imag, y.imag, eps) def test_div(x, y): """Compute complex z=x*y, and check that z/x==y and z/y==x.""" |