bpo-46018: Ensure that math.expm1 does not raise on underflow (GH-29997)

(cherry picked from commit 3363e1cb05)

Co-authored-by: Steve Dower <steve.dower@python.org>
This commit is contained in:
Miss Islington (bot) 2021-12-09 11:37:06 -08:00 committed by GitHub
parent 934a24c641
commit ca08655b80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -0,0 +1 @@
Ensure that :func:`math.expm1` does not raise on underflow.

View file

@ -977,9 +977,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,