Skip to content
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
Expand comments to explain why we ignore errno
  • Loading branch information
hpkfft committed Sep 18, 2026
commit be0ed872f22216dd8bf99ed76071302e215953d8
6 changes: 4 additions & 2 deletions Modules/cmathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,10 @@ cmath_phase_impl(PyObject *module, Py_complex z)
{
double phi;

phi = atan2(z.imag, z.real); /* should not cause any exception */
/* gh-153144: Ignore atan2() errno on purpose. */
phi = atan2(z.imag, z.real);
/* gh-153144: Ignore atan2() errno on purpose since it can optionally be
Comment thread
picnixz marked this conversation as resolved.
* EDOM, which we should ignore, or ERANGE if phi underflows,
* which is silent on Python. Overflow is not possible. */
Comment thread
skirpichev marked this conversation as resolved.
Outdated
return PyFloat_FromDouble(phi);
}

Expand Down
7 changes: 5 additions & 2 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,14 @@ FUNC1(atan, atan, 0,
"atan($module, x, /)\n--\n\n"
"Return the arc tangent (measured in radians) of x.\n\n"
"The result is between -pi/2 and pi/2.")
FUNC2NE(atan2, atan2, // gh-153144: Ignore atan2() errno on purpose.
/* gh-153144: Ignore atan2 and atan2pi errno on purpose since it can optionally
Comment thread
hpkfft marked this conversation as resolved.
* be EDOM, which we should ignore, or ERANGE on underflow, which is
* silent on Python. Overflow is not possible. */
Comment on lines +1154 to +1156

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* gh-153144: Ignore atan2 and atan2pi errno on purpose since it can optionally
* be EDOM, which we should ignore, or ERANGE on underflow, which is
* silent on Python. Overflow is not possible. */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vstinner asked for the "ignore errno on purpose" part of this comment on August 14: #153148 (comment)
@picnixz asked to "document the reason why we ignore errno in this case" on September 18: #153148 (comment)

FUNC2NE(atan2, atan2,
Comment thread
hpkfft marked this conversation as resolved.
"atan2($module, y, x, /)\n--\n\n"
"Return the arc tangent (measured in radians) of y/x.\n\n"
"Unlike atan(y/x), the signs of both x and y are considered.")
FUNC2NE(atan2pi, m_atan2pi, // gh-153144: Ignore atan2pi() errno on purpose.
FUNC2NE(atan2pi, m_atan2pi,
"atan2pi($module, y, x, /)\n--\n\n"
"Return the arc tangent (measured in half-turns) of y/x.\n\n"
"Unlike atanpi(y/x), the signs of both x and y are considered.")
Expand Down