[Python-checkins] python/dist/src/Include floatobject.h, 2.22, 2.23 pythonrun.h, 2.65, 2.66

mwh@users.sourceforge.net mwh at users.sourceforge.net
Fri May 27 17:23:46 CEST 2005


Update of /cvsroot/python/python/dist/src/Include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14998/Include

Modified Files:
	floatobject.h pythonrun.h 
Log Message:
This is my patch:

[ 1181301 ] make float packing copy bytes when they can

which hasn't been reviewed, despite numerous threats to check it in
anyway if noone reviews it.  Please read the diff on the checkin list,
at least!

The basic idea is to examine the bytes of some 'probe values' to see if
the current platform is a IEEE 754-ish platform, and if so
_PyFloat_{Pack,Unpack}{4,8} just copy bytes around.

The rest is hair for testing, and tests.



Index: floatobject.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/floatobject.h,v
retrieving revision 2.22
retrieving revision 2.23
diff -u -d -r2.22 -r2.23
--- floatobject.h	20 Mar 2003 20:53:29 -0000	2.22
+++ floatobject.h	27 May 2005 15:23:13 -0000	2.23
@@ -55,13 +55,18 @@
  * routines produce a C double from such a string.  The suffix (4 or 8)
  * specifies the number of bytes in the string.
  *
- * Excepting NaNs and infinities (which aren't handled correctly), the 4-
- * byte format is identical to the IEEE-754 single precision format, and
- * the 8-byte format to the IEEE-754 double precision format.  On non-
- * IEEE platforms with more precision, or larger dynamic range, than
- * 754 supports, not all values can be packed; on non-IEEE platforms with
- * less precision, or smaller dynamic range, not all values can be
- * unpacked.  What happens in such cases is partly accidental (alas).
+ * On platforms that appear to use (see _PyFloat_Init()) IEEE-754 formats
+ * these functions work by copying bits.  On other platforms, the formats the
+ * 4- byte format is identical to the IEEE-754 single precision format, and
+ * the 8-byte format to the IEEE-754 double precision format, although the
+ * packing of INFs and NaNs (if such things exist on the platform) isn't
+ * handled correctly, and attempting to unpack a string containing an IEEE
+ * INF or NaN will raise an exception.
+ *
+ * On non-IEEE platforms with more precision, or larger dynamic range, than
+ * 754 supports, not all values can be packed; on non-IEEE platforms with less
+ * precision, or smaller dynamic range, not all values can be unpacked.  What
+ * happens in such cases is partly accidental (alas).
  */
 
 /* The pack routines write 4 or 8 bytes, starting at p.  le is a bool
@@ -70,8 +75,9 @@
  * first, at p).
  * Return value:  0 if all is OK, -1 if error (and an exception is
  * set, most likely OverflowError).
- * Bug:  What this does is undefined if x is a NaN or infinity.
- * Bug:  -0.0 and +0.0 produce the same string.
+ * There are two problems on non-IEEE platforms:
+ * 1):  What this does is undefined if x is a NaN or infinity.
+ * 2):  -0.0 and +0.0 produce the same string.
  */
 PyAPI_FUNC(int) _PyFloat_Pack4(double x, unsigned char *p, int le);
 PyAPI_FUNC(int) _PyFloat_Pack8(double x, unsigned char *p, int le);
@@ -81,9 +87,8 @@
  * last, at p+3 or p+7), false if big-endian (exponent first, at p).
  * Return value:  The unpacked double.  On error, this is -1.0 and
  * PyErr_Occurred() is true (and an exception is set, most likely
- * OverflowError).
- * Bug:  What this does is undefined if the string represents a NaN or
- * infinity.
+ * OverflowError).  Note that on a non-IEEE platform this will refuse
+ * to unpack a string that represents a NaN or infinity.
  */
 PyAPI_FUNC(double) _PyFloat_Unpack4(const unsigned char *p, int le);
 PyAPI_FUNC(double) _PyFloat_Unpack8(const unsigned char *p, int le);

Index: pythonrun.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/pythonrun.h,v
retrieving revision 2.65
retrieving revision 2.66
diff -u -d -r2.65 -r2.66
--- pythonrun.h	7 Oct 2004 03:58:06 -0000	2.65
+++ pythonrun.h	27 May 2005 15:23:13 -0000	2.66
@@ -105,6 +105,7 @@
 PyAPI_FUNC(void) _PyImportHooks_Init(void);
 PyAPI_FUNC(int) _PyFrame_Init(void);
 PyAPI_FUNC(int) _PyInt_Init(void);
+PyAPI_FUNC(void) _PyFloat_Init(void);
 
 /* Various internal finalizers */
 PyAPI_FUNC(void) _PyExc_Fini(void);



More information about the Python-checkins mailing list