Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!stormy.atmos.washington.edu!jeff From: jeff@stormy.atmos.washington.edu (Jeff L. Bowden) Newsgroups: comp.lang.c Subject: Math functions (was Re: C optimizer) Message-ID: Date: 13 Feb 89 20:26:08 GMT References: <515@larry.UUCP> <795@atanasoff.cs.iastate.edu> Sender: news@beaver.cs.washington.edu Distribution: comp Organization: Ministry of Silly Walks Lines: 23 In-reply-to: hascall@atanasoff.cs.iastate.edu's message of 13 Feb 89 18:32:03 GMT In article <795@atanasoff.cs.iastate.edu> hascall@atanasoff.cs.iastate.edu (John Hascall) writes: >In article <515@larry.UUCP> jwp@larry.UUCP (Jeffrey W Percival) writes: >>I have a question about how much optimizing I should worry about when <>writing programs in C. Suppose I have this code fragment: > <> x = (1 + cos(r)) / (cos(r) * sin(r)); >> y = (cos(r) - sin(r)) / (1 + sin(r)); < >>I made this up, but the point is the re-use of the sin() and cos() <>calls. Now, can I expect the compiler to form only one call to sin and >>cos? ... < > I think it will/should call the function each time it appears as < the compiler has no way of knowing the "side-effects" of a > function call (i.e., file operations, accessing global variables, etc). Even if the compiler knew something about the math functions (i.e. they are not going to do i/o with the user) it still might have to generate the calls. I have heard that for math libraries to be IEEE conformant they must round up and down on .5 *randomly* with a uniform distribution. I was floored when I heard this. Anyone know if it is actually true? -- "Security and Liberty are at war. Which side are you on?"