Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!ucsd!nosc!cod!mball From: mball@cod.NOSC.MIL (Michael S. Ball) Newsgroups: comp.lang.c Subject: Re: C optimizer Keywords: C pure function optimization Message-ID: <1404@cod.NOSC.MIL> Date: 14 Feb 89 05:58:00 GMT References: <515@larry.UUCP> <9648@smoke.BRL.MIL> Reply-To: mball@cod.nosc.mil.UUCP (Michael S. Ball) Organization: TauMetric Corporation Lines: 18 In article <515@larry.UUCP> jwp@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@cod.nosc.mil