summaryrefslogtreecommitdiff
path: root/Modules/mathmodule.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2021-12-09 18:31:54 +0000
committerGitHub <noreply@github.com>2021-12-09 18:31:54 +0000
commit3363e1cb05d0d19ed172ea63606d8cb6268747fc (patch)
tree4a387cf8f7cc9b6822607b3b4856e097ad892908 /Modules/mathmodule.c
parent44b0e76f2a80c9a78242b7542b8b1218d244af07 (diff)
downloadcpython-git-3363e1cb05d0d19ed172ea63606d8cb6268747fc.tar.gz
bpo-46018: Ensure that math.expm1 does not raise on underflow (GH-29997)
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r--Modules/mathmodule.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 84b5b954b1..011ce0afd3 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -985,9 +985,13 @@ is_error(double x)
* On some platforms (Ubuntu/ia64) it seems that errno can be
* set to ERANGE for subnormal results that do *not* underflow
* to zero. So to be safe, we'll ignore ERANGE whenever the
- * function result is less than one in absolute value.
+ * function result is less than 1.5 in absolute value.
+ *
+ * bpo-46018: Changed to 1.5 to ensure underflows in expm1()
+ * are correctly detected, since the function may underflow
+ * toward -1.0 rather than 0.0.
*/
- if (fabs(x) < 1.0)
+ if (fabs(x) < 1.5)
result = 0;
else
PyErr_SetString(PyExc_OverflowError,