Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!ucbvax!SUN.COM!wmb From: wmb@SUN.COM (Mitch Bradley) Newsgroups: comp.lang.forth Subject: double precision arithmetic in C Message-ID: <8912301506.AA00638@jade.berkeley.edu> Date: 29 Dec 89 21:21:38 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Forth Interest Group International List Organization: The Internet Lines: 19 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