diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-12-09 18:55:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-09 18:55:53 (GMT) |
commit | 5ae4265b8c8042c496e569b6dbf9ef107e1d5b31 (patch) | |
tree | 44038a4e1361e794723aeb8a9873ba374e623bf7 /Modules | |
parent | 25254d484248f5a555d30209f455b8d8ee2e72df (diff) | |
download | cpython-5ae4265b8c8042c496e569b6dbf9ef107e1d5b31.zip cpython-5ae4265b8c8042c496e569b6dbf9ef107e1d5b31.tar.gz cpython-5ae4265b8c8042c496e569b6dbf9ef107e1d5b31.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>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/mathmodule.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index c974601..1f16849 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -971,9 +971,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, |