Math functions (was Re: C optimizer)
Jeff L. Bowden
jeff at stormy.atmos.washington.edu
Tue Feb 14 06:26:08 AEST 1989
In article <795 at atanasoff.cs.iastate.edu> hascall at atanasoff.cs.iastate.edu (John Hascall) writes:
>In article <515 at larry.UUCP> jwp at 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?"
More information about the Comp.lang.c
mailing list