summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-27 22:38:36 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-27 22:38:36 (GMT)
commit715ec1818de43836cffea50d5f4b5e53fc68a849 (patch)
tree0c6fca13960a035e451fbda4b1d2839afa7e26d9 /Lib
parentb61a1f5219fb52d3d5a6a8bee427b94efeee4894 (diff)
downloadcpython-715ec1818de43836cffea50d5f4b5e53fc68a849.zip
cpython-715ec1818de43836cffea50d5f4b5e53fc68a849.tar.gz
cpython-715ec1818de43836cffea50d5f4b5e53fc68a849.tar.bz2
Patch # 1507 by Mark Dickinson. Make complex(x, -0) retain the sign of
the imaginary part (as long as it's not complex). Backport candidate?
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_complex.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 3035c2d..64297e2 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -9,6 +9,7 @@ warnings.filterwarnings(
)
from random import random
+from math import atan2
# These tests ensure that complex math does the right thing
@@ -225,6 +226,18 @@ class ComplexTest(unittest.TestCase):
self.assertAlmostEqual(complex(real=17+23j, imag=23), 17+46j)
self.assertAlmostEqual(complex(real=1+2j, imag=3+4j), -3+5j)
+ # check that the sign of a zero in the real or imaginary part
+ # is preserved when constructing from two floats. (These checks
+ # are harmless on systems without support for signed zeros.)
+ def split_zeros(x):
+ """Function that produces different results for 0. and -0."""
+ return atan2(x, -1.)
+
+ self.assertEqual(split_zeros(complex(1., 0.).imag), split_zeros(0.))
+ self.assertEqual(split_zeros(complex(1., -0.).imag), split_zeros(-0.))
+ self.assertEqual(split_zeros(complex(0., 1.).real), split_zeros(0.))
+ self.assertEqual(split_zeros(complex(-0., 1.).real), split_zeros(-0.))
+
c = 3.14 + 1j
self.assert_(complex(c) is c)
del c