diff Objects/floatobject.c @ 49104:974040c8f369 legacy-trunk

#3777: long(4.2) returned an int, and broke backward compatibility. the __long__ slot is allowed to return either int or long, but the behaviour of float objects should not change between 2.5 and 2.6. Reviewed by Benjamin Peterson
author Amaury Forgeot d'Arc <amauryfa@gmail.com>
date Tue, 09 Sep 2008 07:24:30 +0000
parents e39d44adb618
children f3da56e3fce4
line wrap: on
line diff
--- a/Objects/floatobject.c	Tue Sep 09 00:49:16 2008 +0000
+++ b/Objects/floatobject.c	Tue Sep 09 07:24:30 2008 +0000
@@ -1105,6 +1105,13 @@
 }
 
 static PyObject *
+float_long(PyObject *v)
+{
+	double x = PyFloat_AsDouble(v);
+	return PyLong_FromDouble(x);
+}
+
+static PyObject *
 float_float(PyObject *v)
 {
 	if (PyFloat_CheckExact(v))
@@ -1897,7 +1904,7 @@
 	0,		/*nb_or*/
 	float_coerce, 	/*nb_coerce*/
 	float_trunc, 	/*nb_int*/
-	float_trunc, 	/*nb_long*/
+	float_long, 	/*nb_long*/
 	float_float,	/*nb_float*/
 	0,		/* nb_oct */
 	0,		/* nb_hex */