mirror of
https://github.com/python/cpython.git
synced 2025-10-05 22:51:56 +00:00
[3.6] fixes bpo-31373: fix undefined floating-point demotions (GH-3396) (#3424)
(cherry picked from commit a853a8ba78
)
This commit is contained in:
parent
b0d0217c0e
commit
b03623227e
5 changed files with 51 additions and 30 deletions
|
@ -2182,13 +2182,15 @@ _PyFloat_Pack4(double x, unsigned char *p, int le)
|
|||
|
||||
}
|
||||
else {
|
||||
float y = (float)x;
|
||||
const unsigned char *s = (unsigned char*)&y;
|
||||
int i, incr = 1;
|
||||
|
||||
if (Py_IS_INFINITY(y) && !Py_IS_INFINITY(x))
|
||||
if (fabs(x) > FLT_MAX && !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)
|
||||
|| (float_format == ieee_big_endian_format && le)) {
|
||||
p += 3;
|
||||
|
@ -2196,7 +2198,7 @@ _PyFloat_Pack4(double x, unsigned char *p, int le)
|
|||
}
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
*p = *s++;
|
||||
*p = s[i];
|
||||
p += incr;
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue