C optimizer
Michael S. Ball
mball at cod.NOSC.MIL
Tue Feb 14 15:58:00 AEST 1989
In article <515 at larry.UUCP> jwp at larry.UUCP (Jeffrey W Percival) writes:
> x = (1 + cos(r)) / (cos(r) * sin(r));
> y = (cos(r) - sin(r)) / (1 + sin(r));
>Now, can I expect the compiler to form only one call to sin and cos?
In K&R C this is impossible, as many have mentioned. The draft ANSI standard
makes it possible, though not too many take advantage of it. The Oregon
Software C & C++ compiler uses the trick proposed in the standard and uses
a macro to convert the math functions to built-in functions. These are known
to be pure and are so optimized. In fact, if the target machine has a
math chip the simple math functions are compiled inline as single instructions.
-Mike Ball-
TauMetric Corporation
1094 Cudahy Pl. Ste 302
San Diego, CA 92110
(619)275-6381
mball at cod.nosc.mil
More information about the Comp.lang.c
mailing list