summaryrefslogtreecommitdiffstats
path: root/Objects/intobject.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-04 06:17:36 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-04 06:17:36 (GMT)
commite2a600099d3b61327aba5be94d30d40773faa2c9 (patch)
tree7f9ed79ab6f997c2afbeae21bb097d045c344e66 /Objects/intobject.c
parent9c1d7fd5f2173dc72ecdb1df7816c7e432437e02 (diff)
downloadcpython-e2a600099d3b61327aba5be94d30d40773faa2c9.zip
cpython-e2a600099d3b61327aba5be94d30d40773faa2c9.tar.gz
cpython-e2a600099d3b61327aba5be94d30d40773faa2c9.tar.bz2
Change long/long true division to return as many good bits as it can;
e.g., (1L << 40000)/(1L << 40001) returns 0.5, not Inf or NaN or whatever.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r--Objects/intobject.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 775213c..73d5e77 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -535,7 +535,14 @@ int_classic_div(PyIntObject *x, PyIntObject *y)
static PyObject *
int_true_divide(PyObject *v, PyObject *w)
{
- return PyFloat_Type.tp_as_number->nb_true_divide(v, w);
+ /* If they aren't both ints, give someone else a chance. In
+ particular, this lets int/long get handled by longs, which
+ underflows to 0 gracefully if the long is too big to convert
+ to float. */
+ if (PyInt_Check(v) && PyInt_Check(w))
+ return PyFloat_Type.tp_as_number->nb_true_divide(v, w);
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
}
static PyObject *