summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_complex.py
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2017-02-20 20:28:15 (GMT)
committerGitHub <noreply@github.com>2017-02-20 20:28:15 (GMT)
commit112ec38c15b388fe025ccb85369a584d218b1160 (patch)
tree411b56a68f3900436949eb6ce1a49a8f6c035826 /Lib/test/test_complex.py
parent1b8df107f867fb05ff39ebee7c55f0a907e7ad5f (diff)
downloadcpython-112ec38c15b388fe025ccb85369a584d218b1160.zip
cpython-112ec38c15b388fe025ccb85369a584d218b1160.tar.gz
cpython-112ec38c15b388fe025ccb85369a584d218b1160.tar.bz2
bpo-29602: fix signed zero handling in complex constructor. (#203)
* Fix incorrect handling of signed zeros for complex-related classes. * Add Misc/NEWS entry.
Diffstat (limited to 'Lib/test/test_complex.py')
-rw-r--r--Lib/test/test_complex.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index c249ca7..cee4934 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -387,6 +387,29 @@ class ComplexTest(unittest.TestCase):
self.assertAlmostEqual(complex(complex1(1j)), 2j)
self.assertRaises(TypeError, complex, complex2(1j))
+ @support.requires_IEEE_754
+ def test_constructor_special_numbers(self):
+ class complex2(complex):
+ pass
+ for x in 0.0, -0.0, INF, -INF, NAN:
+ for y in 0.0, -0.0, INF, -INF, NAN:
+ with self.subTest(x=x, y=y):
+ z = complex(x, y)
+ self.assertFloatsAreIdentical(z.real, x)
+ self.assertFloatsAreIdentical(z.imag, y)
+ z = complex2(x, y)
+ self.assertIs(type(z), complex2)
+ self.assertFloatsAreIdentical(z.real, x)
+ self.assertFloatsAreIdentical(z.imag, y)
+ z = complex(complex2(x, y))
+ self.assertIs(type(z), complex)
+ self.assertFloatsAreIdentical(z.real, x)
+ self.assertFloatsAreIdentical(z.imag, y)
+ z = complex2(complex(x, y))
+ self.assertIs(type(z), complex2)
+ self.assertFloatsAreIdentical(z.real, x)
+ self.assertFloatsAreIdentical(z.imag, y)
+
def test_underscores(self):
# check underscores
for lit in VALID_UNDERSCORE_LITERALS: