C language hacking
Cesar Quiroz
quiroz at rochester.UUCP
Tue Nov 13 01:10:53 AEST 1984
>(from a recent posting :)
> I find that frequently I need both the quotient and remainder of
> two integers: a / b a % b
> Since most (maybe all) machine architectures compute these at the
> same time, it sure would be nice to be able to get both results
> rather than wastefully reexecuting precisely the same instructions
> a second time. This becomes particularly bothersome when "a" & "b"
> are fairly complicated expressions. I have no idea what a good
> syntax for such an operation would be.
>
> It would also be nice if sin( x ) and cos( x ) could be computed
> simultaneously with reduced cost. I doubt if this is possible
> but would like to know if it is.
Both are reasonable expectations, but seem to have a place in a standard
library rather than in the syntax of the language.
The sin/cos simultaneous computing is something you can program in C
completely. Getting both quotient and remainder at the same time cannot
(at least not without incurring a procedure call, which denies the
advantage) and you may have a point if you expect the compiler to
recognize something like:
intdiv(a,b,&q,&r);
and expand it in line. However, it may be too much additional overhead
for the gains. In such a case, you may feel forced to write assem...
(no I didn't mean to type that!).
Cesar
More information about the Comp.lang.c
mailing list