wmb@SUN.COM (Mitch Bradley) (12/30/89)
I just discovered an easy way to develop carry and borrow for implementing multiple precision arithmetic in C. This way is easier and faster than my previous solution (posted some time ago). #define CARRY(a,b) ((unsigned)a >= (unsigned)(-b)) #define BORROW(a,b) ((unsigned)a < (unsigned)b) This method assumes 2's complement arithmetic. My previous solution for CARRY computed a logical function involving the sign bits of the arguments and the result, similar to the way it is usually done in hardware. I discovered this new solution while implementing D- ; the definition of BORROW is pretty obvious in retrospect, and then I got to thinking that there must be a symmetrical solution for CARRY. Proof of the correctness is left to the reader as an exercise (Hint: draw a number circle and consider negation as reflection about the axis). Mitch