[Python-checkins] r60856 - python/branches/trunk-math/Lib/test/test_complex.py
christian.heimes
python-checkins at python.org
Sat Feb 16 11:33:09 CET 2008
Author: christian.heimes
Date: Sat Feb 16 11:33:09 2008
New Revision: 60856
Modified:
python/branches/trunk-math/Lib/test/test_complex.py
Log:
More tests for complex IEEE 754 division. I'm a little bit surprised that complex(-1) / 0 returns complex(inf, inf) and not complex(-inf, inf) ...
Modified: python/branches/trunk-math/Lib/test/test_complex.py
==============================================================================
--- python/branches/trunk-math/Lib/test/test_complex.py (original)
+++ python/branches/trunk-math/Lib/test/test_complex.py Sat Feb 16 11:33:09 2008
@@ -9,7 +9,8 @@
)
from random import random
-from math import atan2, pi
+from math import atan2, pi, isinf, isnan, copysign
+from contextlib import ieee754
INF = float("inf")
NAN = float("nan")
@@ -52,6 +53,16 @@
def assertIs(self, a, b):
self.assert_(a is b)
+ def assertInf(self, a, real_sign=1, imag_sign=1):
+ self.assert_(isinf(a.real), a)
+ self.assertEqual(copysign(1, a.real), real_sign)
+ self.assert_(isinf(a.imag), a)
+ self.assertEqual(copysign(1, a.imag), imag_sign)
+
+ def assertNan(self, a):
+ self.assert_(isnan(a.real), a)
+ self.assert_(isnan(a.imag), a)
+
def check_div(self, x, y):
"""Compute complex z=x*y, and check that z/x==y and z/y==x."""
z = x * y
@@ -99,6 +110,18 @@
self.assertAlmostEqual(complex.__floordiv__(3+0j, 1.5+0j), 2)
self.assertRaises(ZeroDivisionError, complex.__floordiv__, 3+0j, 0+0j)
+ def test_div_ieee754(self):
+ with ieee754():
+ self.assertInf(complex(1., 0) / complex(0.), 1, 1)
+ self.assertInf(complex(-1., 0) / complex(0.), 1, 1)
+ self.assertInf(complex(0, 1.) / complex(0.), 1, 1)
+ self.assertInf(complex(0, -1.) / complex(0.), 1, -1)
+ self.assertInf(complex(1., 1.) / complex(0.), 1, 1)
+ self.assertInf(complex(1., -1.) / complex(0.), 1, -1)
+ self.assertInf(complex(-1., 1.) / complex(0.), 1, 1)
+ self.assertInf(complex(-1., -1.) / complex(0.), -1, 1)
+ self.assertNan(complex(0.) / complex(0.))
+
def test_coerce(self):
self.assertRaises(OverflowError, complex.__coerce__, 1+1j, 1L<<10000)
More information about the Python-checkins
mailing list