Long Longs

Robert D. Silverman bs at faron.UUCP
Thu Feb 27 21:56:02 AEST 1986


Much of the work I (and others) do involves frequent computations of
the form:

int a,b,c,d;

a = (b*c)/d;
a = (b*c) % d;


Even when I know (because of normalization or other conditions) that
a will fit in a single machine word, C does not allow one to do such
computations. The difficulty of course is that b*c frequently will
overflow. However, many machines CAN multiply two full words together
giving a double length product placed in two adjacent registers. 
Since there is no 'double register int a' or 'long long a' in C, one
is forced however to write an assembler routine to do such arithmetic.
However, if one does such computations frequently (e.g. millions of
times) the cost of calling a routine to do it is prohibitive.
e.g. A three argument call on the VAX takes 16+ usec. 

Does anyone have a good solution?
 
Does C++ have long longs? Does anyone know of ANY language that does?
(Bignums in Lisp don't qualify)
 
 
Bob Silverman



More information about the Comp.lang.c mailing list