mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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.
This commit is contained in:
parent
9c1d7fd5f2
commit
e2a600099d
3 changed files with 78 additions and 2 deletions
|
@ -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 *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue