]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46018: Ensure that math.expm1 does not raise on underflow (GH-29997)
authorSteve Dower <steve.dower@python.org>
Thu, 9 Dec 2021 18:31:54 +0000 (18:31 +0000)
committerGitHub <noreply@github.com>
Thu, 9 Dec 2021 18:31:54 +0000 (18:31 +0000)
Misc/NEWS.d/next/Library/2021-12-09-00-44-42.bpo-46018.hkTI7v.rst [new file with mode: 0644]
Modules/mathmodule.c

diff --git a/Misc/NEWS.d/next/Library/2021-12-09-00-44-42.bpo-46018.hkTI7v.rst b/Misc/NEWS.d/next/Library/2021-12-09-00-44-42.bpo-46018.hkTI7v.rst
new file mode 100644 (file)
index 0000000..6ff76f5
--- /dev/null
@@ -0,0 +1 @@
+Ensure that :func:`math.expm1` does not raise on underflow.
index 84b5b954b10513474fbf71127105b8e3c9f397eb..011ce0afd3aecf5a9a1d1336f528436b0f8a70cb 100644 (file)
@@ -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,