Repository navigation
gh-161972: Fix cmath.log(0, base) returning (-inf+nanj) instead of raising ValueError #161986
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||
| Fix :func:`cmath.log` with a nonzero base: ``cmath.log(0, base)`` now raises :exc:`ValueError` instead of returning ``(-inf+nanj)``. | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -634,7 +634,6 @@ c_log(Py_complex z) | |
| } | ||
| } | ||
| r.imag = atan2(z.imag, z.real); | ||
| errno = 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to leave c_log() unchanged: c_xxx() functions are documented to set errno to 0 on success, see #161972 (comment). Instead, check errno after the first c_log() call in cmath_log_impl(). Something like: {
x = c_log(x);
if (errno != 0) {
return math_error();
}
if (y_obj != NULL) {
Py_complex y = PyComplex_AsCComplex(y_obj);
if (PyErr_Occurred()) {
return NULL;
}
y = c_log(y);
if (errno != 0) {
return math_error();
}
x = _Py_c_quot(x, y);
}
return PyComplex_FromCComplex(x);
}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return r; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmath.log(2, 0)doesn't callcmath.log(0, base), so I suggest to rename the test to:I would prefer to add the new test at the end of the
CMathTestsclass.