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 1 commit
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
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
  • Loading branch information
skirpichev and picnixz authored Jun 1, 2025
commit cea09b7da01460b9d2dfdf92621daddb1ae35b9c
6 changes: 3 additions & 3 deletions Doc/library/cmath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ the function is then applied to the result of the conversion.
1.4142135623730951j


Most functions computes and returns the C99 Annex G recommended result. If the
Most functions compute and return the C99 Annex G recommended result. If the
standard recommends raising ``FE_DIVBYZERO`` or ``FE_INVALID`` floating-point
exceptions --- the :exc:`ValueError` is raised and recommended result available
as the ``value`` attribute of the exception object.
exceptions --- a :exc:`ValueError` is raised and the recommended result
is available as the ``value`` attribute of the exception object.


==================================================== ============================================
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ cmath
-----

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


Expand Down
4 changes: 2 additions & 2 deletions Modules/cmathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (errno == EDOM) {
if (value) {
PyObject_SetAttrString(exc, "value", value);
}
Py_DECREF(value);
Py_XDECREF(value);
PyErr_SetRaisedException(exc);
goto exit;
}
Expand Down Expand Up @@ -907,7 +907,7 @@ cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj)
if (value) {
PyObject_SetAttrString(exc, "value", value);
}
Py_DECREF(value);
Py_XDECREF(value);
PyErr_SetRaisedException(exc);
}
return ret;
Expand Down
Loading