Skip to content

Commit 82448e1

Browse files
committed
Add cmath tests and update NEWS entry
1 parent f4ed052 commit 82448e1

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

Lib/test/test_cmath.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,16 @@ def test_phase(self):
421421
self.assertEqual(phase(complex(-0.0, 0.0)), pi)
422422
self.assertEqual(phase(complex(-0.0, -0.0)), -pi)
423423

424+
# overflow and underflow of imag/real
425+
self.assertEqual(phase(complex(1E300, 1E-320)), 0.0)
426+
self.assertEqual(phase(complex(1E300, -1E-320)), -0.0)
427+
self.assertAlmostEqual(phase(complex(1E-320, 1E300)), pi/2)
428+
self.assertAlmostEqual(phase(complex(-1E-320, 1E300)), pi/2)
429+
self.assertAlmostEqual(phase(complex(-1E300, 1E-320)), pi)
430+
self.assertAlmostEqual(phase(complex(-1E300, -1E-320)), -pi)
431+
self.assertAlmostEqual(phase(complex(1E-320, -1E300)), -pi/2)
432+
self.assertAlmostEqual(phase(complex(-1E-320, -1E300)), -pi/2)
433+
424434
# infinities
425435
self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi)
426436
self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
The return values of ``atan2(0.0, 0.0)``, ``atan2(0.0, -0.0)``, etc. are
2-
specified in Annex F of the C standard. The Intel and Solaris math libraries
3-
also set ``errno`` to indicate a domain error when both arguments are zero.
4-
Python's :func:`math.atan2`, :func:`math.atan2pi`, and :func:`cmath.phase`
5-
should return the values specified by Annex F, not raise ``ValueError``.
6-
This patch ignores ``errno`` for the C ``atan2()`` and ``atan2pi()`` functions.
1+
Given a complex number ``z`` for which ``z.imag/z.real`` underflows to zero,
2+
the :func:`cmath.phase` of ``z`` should not raise ``OverflowError``. Also,
3+
given arguments of zero, Python's :func:`math.atan2`, :func:`math.atan2pi`,
4+
and :func:`cmath.phase` should return the values specified by Annex F of the
5+
C standard, not raise ``ValueError``, regardless of whether the platform's
6+
math library sets ``errno`` for ``atan2(0.0, 0.0)``, ``atan2(0.0, -0.0)``, etc.
77
Contributed by High Performance Kernels LLC.

0 commit comments

Comments
 (0)