Skip to content

Commit ca08655

Browse files
bpo-46018: Ensure that math.expm1 does not raise on underflow (GH-29997)
(cherry picked from commit 3363e1c) Co-authored-by: Steve Dower <[email protected]>
1 parent 934a24c commit ca08655

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,13 @@ is_error(double x)
977977
* On some platforms (Ubuntu/ia64) it seems that errno can be
978978
* set to ERANGE for subnormal results that do *not* underflow
979979
* to zero. So to be safe, we'll ignore ERANGE whenever the
980-
* function result is less than one in absolute value.
980+
* function result is less than 1.5 in absolute value.
981+
*
982+
* bpo-46018: Changed to 1.5 to ensure underflows in expm1()
983+
* are correctly detected, since the function may underflow
984+
* toward -1.0 rather than 0.0.
981985
*/
982-
if (fabs(x) < 1.0)
986+
if (fabs(x) < 1.5)
983987
result = 0;
984988
else
985989
PyErr_SetString(PyExc_OverflowError,

0 commit comments

Comments
 (0)