8000 gh-133895: provide C99 Annex G return values for cmath's functions by skirpichev · Pull Request #134995 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-133895: provide C99 Annex G return values for cmath's functions #134995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 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
0