Skip to content

Commit 5ae4265

Browse files
miss-islingtonzooba
andauthoredDec 9, 2021
bpo-46018: Ensure that math.expm1 does not raise on underflow (GH-29997)
(cherry picked from commit 3363e1c) Co-authored-by: Steve Dower <steve.dower@python.org>
1 parent 25254d4 commit 5ae4265

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
@@ -971,9 +971,13 @@ is_error(double x)
971971
* On some platforms (Ubuntu/ia64) it seems that errno can be
972972
* set to ERANGE for subnormal results that do *not* underflow
973973
* to zero. So to be safe, we'll ignore ERANGE whenever the
974-
* function result is less than one in absolute value.
974+
* function result is less than 1.5 in absolute value.
975+
*
976+
* bpo-46018: Changed to 1.5 to ensure underflows in expm1()
977+
* are correctly detected, since the function may underflow
978+
* toward -1.0 rather than 0.0.
975979
*/
976-
if (fabs(x) < 1.0)
980+
if (fabs(x) < 1.5)
977981
result = 0;
978982
else
979983
PyErr_SetString(PyExc_OverflowError,

0 commit comments

Comments
 (0)