cwg@m.cs.uiuc.edu (03/03/90)
A question was rasied about how to do double precision integer arithmetic in C without recourse to assembly language procedures. If you allow yourself a "machine constant" MAXINT to be locally defined, it is not difficult. Define an integer pair (am,al) as the most and least significant parts of an integer representation meaning am*BASE+al where BASE is related to MAXINT. For example, if MAXINT is 2^n-1, BASE = 2^{n-1} gives you a little room to move. Then, for addition yoou add the least significant parts and find out if there is a carry by comparing the result against BASE. The smaller BASE is, the more room there is to move and the easier coding is for multiplication etc. If you don't want to have to define machine constants locally, try computing them. (To find MAXINT, shift an even unsigned integer left, and then find out if half of it is the original value.. Keep increasing until this fails.) Of course, this assumes binary machine.