Skip to content
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/library/cmath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ the function is then applied to the result of the conversion.
1.4142135623730951j


Most functions compute and return the C99 Annex G recommended result. If the
standard recommends raising ``FE_DIVBYZERO`` or ``FE_INVALID`` floating-point
exceptions --- a :exc:`ValueError` is raised and the recommended result is
available as the ``value`` attribute of the exception object. If range error
occurs due to overflow in any component of the result --- a :exc:`OverflowError`
is raised.


==================================================== ============================================
**Conversions to and from polar coordinates**
--------------------------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ New modules
Improved modules
================

cmath
-----

* Provide C99 Annex G return values for :mod:`cmath`'s functions as the
``value`` attribute of exception objects.
(Contributed by Sergey B Kirpichev in :gh:`133895`.)


dbm
---

Expand Down
13 changes: 7 additions & 6 deletions Lib/test/test_cmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,23 @@ def polar_complex(z):
if 'divide-by-zero' in flags or 'invalid' in flags:
try:
actual = function(arg)
except ValueError:
continue
except ValueError as exc:
actual = exc.value
else:
self.fail('ValueError not raised in test '
'{}: {}(complex({!r}, {!r}))'.format(id, fn, ar, ai))

if 'overflow' in flags:
elif 'overflow' in flags:
try:
actual = function(arg)
except OverflowError:
continue
except OverflowError as exc:
actual = exc.value if fn != 'polar' else complex(*exc.value)
else:
self.fail('OverflowError not raised in test '
'{}: {}(complex({!r}, {!r}))'.format(id, fn, ar, ai))

actual = function(arg)
else:
actual = function(arg)

if 'ignore-real-sign' in flags:
actual = complex(abs(actual.real), actual.imag)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Provide C99 Annex G return values for :mod:`cmath`'s functions as the
``value`` attribute of exception objects. Patch by Sergey B Kirpichev.
Loading
Loading