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

Shifted-0, Modular arithmetic

    Date: 28 October 1980 0556-EST
    From: Dave Touretzky at CMU-10A
    Subject:  is it SUPPOSED to do this?
    (setq a (^ 2 34.))   =>  17179869184.
    (+ a a)   =>   -34359738368.	;arithmetic overflow
    (* 2 a)   =>   0			;huh??? doesn't 2*a = a+a?
    (times 2 a)   =>   34359738368.	;correct answer, as a bignum
The intended compiled-code target for the "+" function is the PDP-10
ADD instruction, and for "*" it is the MUL instruction;  this isn't
nearly as bad as it seems, since there are interesting theoretical
properties of 36.-bit, 2's-complement, mid-point zero arithmetic.
The pratical application of this weirdo "ring" is that except near
the "endpoints", it is almost like integer arithmetic;  when the
endpoints are disturbing, then you must use PLUS and TIMES in order
to insure faithfulness to the standard mathematical arithmetic.
You'll only take two orders of magnitude longer time, but sometimes
the price is worth it.