summaryrefslogtreecommitdiff
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2008-03-14 14:23:37 +0000
committerMark Dickinson <dickinsm@gmail.com>2008-03-14 14:23:37 +0000
commitfa0d5311dc6b1cc25b6b64bc7b0e085a3efb77d4 (patch)
treef21dc1af9c76911437cc9becb4b0d43319757d48 /Objects/floatobject.c
parentd602de2c34ec5c9eaec13920dcce3ef012fce413 (diff)
downloadcpython-fa0d5311dc6b1cc25b6b64bc7b0e085a3efb77d4.tar.gz
Issue 705836: Fix struct.pack(">f", 1e40) to behave consistently
across platforms: it should now raise OverflowError on all platforms. (Previously it raised OverflowError only on non IEEE 754 platforms.) Also fix the (already existing) test for this behaviour so that it actually raises TestFailed instead of just referencing it.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 392a037609..0eaca0f7be 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1751,9 +1751,6 @@ PyFloat_Fini(void)
/*----------------------------------------------------------------------------
* _PyFloat_{Pack,Unpack}{4,8}. See floatobject.h.
- *
- * TODO: On platforms that use the standard IEEE-754 single and double
- * formats natively, these routines could simply copy the bytes.
*/
int
_PyFloat_Pack4(double x, unsigned char *p, int le)
@@ -1833,28 +1830,31 @@ _PyFloat_Pack4(double x, unsigned char *p, int le)
/* Done */
return 0;
- Overflow:
- PyErr_SetString(PyExc_OverflowError,
- "float too large to pack with f format");
- return -1;
}
else {
float y = (float)x;
const char *s = (char*)&y;
int i, incr = 1;
+ if (Py_IS_INFINITY(y) && !Py_IS_INFINITY(x))
+ goto Overflow;
+
if ((float_format == ieee_little_endian_format && !le)
|| (float_format == ieee_big_endian_format && le)) {
p += 3;
incr = -1;
}
-
+
for (i = 0; i < 4; i++) {
*p = *s++;
p += incr;
}
return 0;
}
+ Overflow:
+ PyErr_SetString(PyExc_OverflowError,
+ "float too large to pack with f format");
+ return -1;
}
int