Skip to content
Closed
Prev Previous commit
Next Next commit
Merge branch 'main' into gh-101410/math_error_message
  • Loading branch information
CharlieZhao95 committed Jul 22, 2024
commit dc8e593e6d56ac5e3fe4e55f5dcc789c0f876875
2 changes: 1 addition & 1 deletion Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ math_1(PyObject *arg, double (*func) (double), int can_overflow, const char *err
return NULL;
errno = 0;
r = (*func)(x);
if (Py_IS_NAN(r) && !Py_IS_NAN(x)) {
if (isnan(r) && !isnan(x)) {
PyErr_Format(PyExc_ValueError, err_msg, arg); /* invalid arg */

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.

Shouldn't same message be used below on the line 1076 as well (infinite r for finite input)? atanh(-1) is an example.

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.

Shouldn't same message be used below on the line 1076 as well (infinite r for finite input)? atanh(-1) is an example.

I was wondering if there is a function that can have both input and output( NAN r for non-NAN x and infinite r for finite x).

If such a function exists, it may lead to confusing error messages, because one error message corresponds to two scenarios. I haven't thought of such a function yet, please suggest if it exists. :)

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.

Same atanh :)

atanh(2) - for the 1st scenario and atanh(1) - for the second. I doubt it will be confusing if you raise instead something like ValueError("atanh expects an argument from (-1, -1), got %R"). I don't think it does make sense to have a different descriptions for pole errors (like atanh(1)). @mdickinson ?

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.

See 9c32ae0 from #102523.

return NULL;
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.