diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-12-09 19:37:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-09 19:37:06 (GMT) |
commit | ca08655b808aed2e3abeb64cb67d98a79a661dda (patch) | |
tree | 0be0196e1b6e25e1edb7ac09b3f51d1c31f34c97 | |
parent | 934a24c641da5bc4bdb724e901adc20f9a5dff40 (diff) | |
download | cpython-ca08655b808aed2e3abeb64cb67d98a79a661dda.zip cpython-ca08655b808aed2e3abeb64cb67d98a79a661dda.tar.gz cpython-ca08655b808aed2e3abeb64cb67d98a79a661dda.tar.bz2 |
bpo-46018: Ensure that math.expm1 does not raise on underflow (GH-29997)
(cherry picked from commit 3363e1cb05d0d19ed172ea63606d8cb6268747fc)
Co-authored-by: Steve Dower <steve.dower@python.org>
-rw-r--r-- | Misc/NEWS.d/next/Library/2021-12-09-00-44-42.bpo-46018.hkTI7v.rst | 1 | ||||
-rw-r--r-- | Modules/mathmodule.c | 8 |
2 files changed, 7 insertions, 2 deletions
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 index 0000000..6ff76f5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-12-09-00-44-42.bpo-46018.hkTI7v.rst @@ -0,0 +1 @@ +Ensure that :func:`math.expm1` does not raise on underflow. diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 16da008..4534176 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -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, |