[Python-bugs-list] Divide overflow (follow-on to bug #88) (PR#169)

Tim Peters tim_one@email.msn.com
Mon, 3 Jan 2000 18:46:16 -0500


[John Machin]
> ...
> There is a dilemma here: BIGNEG / -1 should cause an overflow
> exception, not a crash.

Which it now does.

> Pedantry would say that BIGNEG % -1 should *not* cause an
> exception, but return a result of zero.

The Lang Ref (section 5.6, Binary arithmetic operations) guarantees that

    x == (x/y)*y + (x%y)
and
    divmod(x, y) == x/y, x%y

for integer x and y, so if you can compute any one of {divmod(x,y), x/y,
x%y} without exception, you have every right to insist all three be
computable without exception, and to insist that the results satisfy these
identities.  So the *truly* pedantic <wink> answer is the one that's
implemented.

> ... I'm just suggesting that this be added to the documentation
> in the reference manual.

Just noting that the docs currently define no case of OverflowError, let
alone this end case.