Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions Doc/library/cmath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ 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.


==================================================== ============================================
**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 the :exc:`ValueError` exception object.
(Contributed by Sergey B Kirpichev in :gh:`133895`.)


dbm
---

Expand Down
9 changes: 5 additions & 4 deletions Lib/test/test_cmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ 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:
Expand All @@ -333,7 +333,8 @@ def polar_complex(z):
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,3 @@
Provide C99 Annex G return values for :mod:`cmath`'s functions as the
`value`` attribute of the :exc:`ValueError` exception object. Patch by Sergey B
Kirpichev.
162 changes: 159 additions & 3 deletions Modules/clinic/cmathmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading