[R6RS] fixnum operators and overflow detection

William D Clinger will at ccs.neu.edu
Wed Mar 29 16:35:00 EST 2006


Kent wrote:
> We've talked about this before but without any resolution.
> 
> I would prefer that the fixnum operators, including at least fx+, fx*,
> fx-, and the fx shift left operator(s), signal an error when the exact
> representation cannot be represented as a fixnum.  This is the way they
> work in Chez Scheme, and this has caught several errors that might
> otherwise have gone undetected otherwise.

I think there is general agreement that all of the following
are useful:

    fixnum operations that perform arithmetic modulo 2^N
    fixnum operations that perform arithmetic modulo 2^N
        and also return carry or borrow bits (for + and -)
        or two full fixnum results (for *)
    fixnum operations that signal an error on overflow

The first of those three is more convenient than the third
for implementing arbitrary precision integer arithmetic.

The middle of those three is more convenient than either
of the other two for implementing arbitrary precision
integer arithmetic, but is more complex to specify and
is likely to rely on multiple values or other features
that are not uniformly efficient across implementations of
Scheme.

The third of those three is not very convenient for
implementing arbitrary precision integer arithmetic,
which is the main purpose of the fixnum operations in
SRFI 77.  In my opinion, however, it is more useful for
general programming than either the first or second.

I'd like to see both the first and the third in R6RS.  The
first is needed by our reference implementation of integer
arithmetic, and the third is easy to implement in terms of
the first.

If we have both the first and third, then we need naming
conventions to distinguish them.  Regarding the precedent
set by existing implementations, I know of only four that
already implement fixnum operations:

    Bigloo +fx wraps on overflow
    Chez Scheme fx+ signals an overflow
    Gambit ##fixnum.+ wraps on overflow
    Larceny fx+ signals an overflow

If we accept this precedent, then fx+ should signal on
overflow.  Shall we use fixnum+ as name for the version
that wraps modulo 2^N?

Will



More information about the R6RS mailing list