From: Benjamin Peterson Date: Mon, 11 Sep 2017 06:50:46 +0000 (-0700) Subject: bpo-31373: remove overly strict float range checks (#3486) X-Git-Tag: v3.7.0a1~79 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2bb69a5b4e7f96cb35d1b28aa7b7b3974b351f59;p=thirdparty%2FPython%2Fcpython.git bpo-31373: remove overly strict float range checks (#3486) 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. --- diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 66726d6496d6..a16c05cf5d99 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -617,6 +617,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 0b155a170f90..dd7ca9fed15e 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -859,10 +859,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;