New operator: /*

gwyn at BRL-VLD.ARPA gwyn at BRL-VLD.ARPA
Mon Aug 27 17:09:36 AEST 1984


From:      Doug Gwyn (VLD/VMB) <gwyn at BRL-VLD.ARPA>

Try
	short	a, b, c, d;
	d = (long)a * b / c;
The one typecast is sufficient to force all the arithmetic to be done
with long arithmetic, then the result is coerced back into short on
assignment to `d'.  If your compiler is sufficiently clever, it will
take advantage of the fact that the result of the division is only
needed as a short; in any case it is obligated to return the correct
answer.



More information about the Comp.lang.c mailing list