Skip to content

Commit 3363e1c

Browse files
authored
bpo-46018: Ensure that math.expm1 does not raise on underflow (GH-29997)
1 parent 44b0e76 commit 3363e1c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure that :func:`math.expm1` does not raise on underflow.

Modules/mathmodule.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,13 @@ is_error(double x)
985985
* On some platforms (Ubuntu/ia64) it seems that errno can be
986986
* set to ERANGE for subnormal results that do *not* underflow
987987
* to zero. So to be safe, we'll ignore ERANGE whenever the
988-
* function result is less than one in absolute value.
988+
* function result is less than 1.5 in absolute value.
989+
*
990+
* bpo-46018: Changed to 1.5 to ensure underflows in expm1()
991+
* are correctly detected, since the function may underflow
992+
* toward -1.0 rather than 0.0.
989993
*/
990-
if (fabs(x) < 1.0)
994+
if (fabs(x) < 1.5)
991995
result = 0;
992996
else
993997
PyErr_SetString(PyExc_OverflowError,

0 commit comments

Comments
 (0)