[3.6] fixes bpo-31373: fix undefined floating-point demotions (GH-3396) (#3424)

(cherry picked from commit a853a8ba7850381d49b284295dd6f0dc491dbe44)
diff --git a/Python/getargs.c b/Python/getargs.c
index 616c6eb..8fb19f3 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -4,6 +4,7 @@
 #include "Python.h"
 
 #include <ctype.h>
+#include <float.h>
 
 
 #ifdef __cplusplus
@@ -810,6 +811,10 @@
         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;