[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Arithmetic overflow

Kent Pitman points out:

>Please be careful when writing your compilers not to copy the Maclisp bug
>turns into a single-instruction addition, ignoring overflow. Gerry's proposal
>does not specify much of any way to get code that can do that. It was an
>unfortunate mistake since when X and Y are large, the addition can overflow
>and bad values can get returned (something GJS's proposal frowns on).

I agree whole-heartedly.  Like Gerry's proposal, the ASSERT procedure does
not give the programmer the ability to specify that overflow is to be ignored,
though it can be used to assert that a result is within a certain range.

My last fibonacci example was perhaps too subtle.  In computing (fib 40), the
arguments to + are always less than 100000000 (the constant appearing in the
fixnum? procedure), but the result is greater than 100000000.  A compiler that
assumes that the result of an addition is never greater than the operands is
simply buggy.

				Peace, Will Clinger