From 2bb69a5b4e7f96cb35d1b28aa7b7b3974b351f59 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 10 Sep 2017 23:50:46 -0700 Subject: 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. --- Lib/test/test_float.py | 6 ++++++ Lib/test/test_getargs2.py | 6 ++++++ Objects/floatobject.c | 4 ++-- Python/getargs.c | 4 ---- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 66726d6..a16c05c 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 0b155a1..dd7ca9f 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; -- cgit v0.12