From: Benjamin Peterson Date: Tue, 12 Sep 2017 06:08:49 +0000 (-0700) Subject: [3.6] bpo-31373: remove overly strict float range checks (GH-3486) (#3495) X-Git-Tag: v3.6.3rc1~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb356c2ecc0528d47fee2b9f4b32da4fcfb48b3a;p=python [3.6] bpo-31373: remove overly strict float range checks (GH-3486) (#3495) This undoes a853a8ba7850381d49b284295dd6f0dc491dbe44 except for the pytime.c parts. We want to continue to allow IEEE 754 doubles larger than FLT_MAX to be rounded into finite floats. Tests were added to very this behavior. (cherry picked from commit 2bb69a5b4e7f96cb35d1b28aa7b7b3974b351f59) --- diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 6491f458c3..c5ca50c8f7 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -613,6 +613,12 @@ class IEEEFormatTestCase(unittest.TestCase): (' FLT_MAX && !Py_IS_INFINITY(x)) + if (Py_IS_INFINITY(y) && !Py_IS_INFINITY(x)) goto Overflow; unsigned char s[sizeof(float)]; - float y = (float)x; memcpy(s, &y, sizeof(float)); if ((float_format == ieee_little_endian_format && !le) diff --git a/Python/getargs.c b/Python/getargs.c index 8fb19f34ec..1381964206 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -811,10 +811,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, double dval = PyFloat_AsDouble(arg); if (PyErr_Occurred()) RETURN_ERR_OCCURRED; - else if (dval > FLT_MAX) - *p = (float)INFINITY; - else if (dval < -FLT_MAX) - *p = (float)-INFINITY; else *p = (float) dval; break;