]> granicus.if.org Git - python/commitdiff
long_true_divide: reliably force underflow to 0 when the denominator
authorTim Peters <tim.peters@gmail.com>
Thu, 6 Sep 2001 21:59:14 +0000 (21:59 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 6 Sep 2001 21:59:14 +0000 (21:59 +0000)
has more bits than the numerator than can be counted in a C int (yes,
that's unlikely, and no, I'm not adding a test case with a 2 gigabit
long).

Objects/longobject.c

index e9e408db95761c7f65b2d1f4c94eb5ee0aff5abe..c7608aa48af255227e4e0b6532bf311b258b3527 100644 (file)
@@ -1605,6 +1605,8 @@ long_true_divide(PyObject *v, PyObject *w)
        aexp -= bexp;
        if (aexp > INT_MAX / SHIFT)
                goto overflow;
+       else if (aexp < -(INT_MAX / SHIFT))
+               return PyFloat_FromDouble(0.0); /* underflow to 0 */
        errno = 0;
        ad = ldexp(ad, aexp * SHIFT);
        if (Py_OVERFLOWED(ad)) /* ignore underflow to 0.0 */