Skip to content
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

gh-102837: Increase test coverage for the math module #110000

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a1d2c1a
gh-102837: Increase test coverage for the math module
skirpichev Sep 18, 2023
03e8ead
Improve math_2() comment (mention real use-cases for math_2)
skirpichev Sep 18, 2023
26489bb
* trunc: drop _PyType_IsReady() check (L2071) like floor/ceil, L2079
skirpichev Sep 18, 2023
128c81d
* log: L2265
skirpichev Sep 18, 2023
ead9eee
* loghelper: drop inaccessible cases L2234, L2235, L2241. Here arg i…
skirpichev Sep 18, 2023
3a80c78
* dist: L2575, L2577
skirpichev Sep 18, 2023
8b3bb52
* hypot: L2630
skirpichev Sep 18, 2023
4e25c35
* sumprod: L2742, L2752, L2772, L2775, L2779, L2783
skirpichev Sep 19, 2023
7956447
Fix typo in sumprod()
skirpichev Sep 19, 2023
052d7de
* sumprod: L2829, L2833, L2836
skirpichev Sep 19, 2023
b431805
* pow: L2979, L2980
skirpichev Sep 19, 2023
a046568
* prod: L3292, L3306, L3316-3328
skirpichev Sep 19, 2023
d7675d7
Merge branch 'main' into math-cov
skirpichev Sep 28, 2023
96f99cd
Merge branch 'main' into math-cov
skirpichev Oct 6, 2023
3df127e
More efficient (for finite x) handling of special cases in math.modf
skirpichev Oct 6, 2023
5e6d59f
Change error tests in loghelper() to more lightweight versions (x == …
skirpichev Oct 6, 2023
3e8d96f
Explicit tests for non-float objects (amend a1d2c1afbf)
skirpichev Oct 15, 2023
35db224
Amend 8b3bb52420 (use math.sqrt(2) instead)
skirpichev Oct 15, 2023
6844b19
Amend 052d7de86
skirpichev Oct 29, 2023
6037d84
Merge branch 'main' into math-cov
skirpichev Nov 3, 2023
d2c5170
Merge branch 'main' into math-cov
encukou Nov 13, 2023
833d852
Merge branch 'main' into math-cov
serhiy-storchaka Dec 1, 2023
5768395
Merge branch 'main' into math-cov
skirpichev Dec 9, 2023
ad84c4a
Revert PyErr_ExceptionMatches
skirpichev Dec 9, 2023
21bc1b8
Merge branch 'main' into math-cov
skirpichev Apr 2, 2024
d488a1d
Merge branch 'main' into math-cov
skirpichev May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ math_1a(PyObject *arg, double (*func) (double))
The last rule is used to catch overflow on platforms which follow
C89 but for which HUGE_VAL is not an infinity.

For most two-argument functions (copysign, fmod, hypot, atan2)
For most two-argument functions (copysign, remainder, atan2)
these rules are enough to ensure that Python's functions behave as
specified in 'Annex F' of the C99 standard, with the 'invalid' and
'divide-by-zero' floating-point exceptions mapping to Python's
Expand Down Expand Up @@ -2196,10 +2196,12 @@ math_modf_impl(PyObject *module, double x)
double y;
/* some platforms don't do the right thing for NaNs and
infinities, so we take care of special cases directly. */
if (isinf(x))
return Py_BuildValue("(dd)", copysign(0., x), x);
else if (isnan(x))
return Py_BuildValue("(dd)", x, x);
if (!isfinite(x)) {
if (isinf(x))
return Py_BuildValue("(dd)", copysign(0., x), x);
else
return Py_BuildValue("(dd)", x, x);
}

errno = 0;
x = modf(x, &y);
Expand Down Expand Up @@ -2232,14 +2234,14 @@ loghelper(PyObject* arg, double (*func)(double))
}

x = PyLong_AsDouble(arg);
if (x == -1.0 && PyErr_Occurred()) {
if (x == -1.0) {
if (!PyErr_ExceptionMatches(PyExc_OverflowError))
return NULL;
/* Here the conversion to double overflowed, but it's possible
to compute the log anyway. Clear the exception and continue. */
PyErr_Clear();
x = _PyLong_Frexp((PyLongObject *)arg, &e);
if (x == -1.0 && PyErr_Occurred())
if (x == -1.0)
return NULL;
/* Value is ~= x * 2**e, so the log ~= log(x) + log(2) * e. */
result = func(x) + func(2.0) * e;
Expand Down Expand Up @@ -3019,7 +3021,8 @@ math_pow_impl(PyObject *module, double x, double y)
(A) (+/-0.)**negative (-> divide-by-zero)
(B) overflow of x**y with x and y finite
*/
else if (isinf(r)) {
else {
assert(isinf(r));
if (x == 0.)
errno = EDOM;
else
Expand Down