Re: Sine code for ANSI C
From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 05/16/04
- Next message: CBFalconer: "Re: Some Questions Asked in Interview"
- Previous message: Gordon Burditt: "Re: Format of Pointers in Unix"
- In reply to: Joe Wright: "Re: Sine code for ANSI C"
- Next in thread: P.J. Plauger: "Re: Sine code for ANSI C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 16 May 2004 21:21:22 GMT
Joe Wright wrote:
>
... snip ...
>
> 2. Large Angles. The circle is 360 degrees or '2 pi radians'.
> Why is something like..
>
> double r = 52147.3, s;
> s = sin(fmod(r,2*PI));
>
> ..not the solution for large angle argument reduction?
That depends highly on how you compute the fmod. Say you compute
r/(2*PI), truncate it to an integer, multiply by (2*PI), and
subtract that from r. Now you have the difference of two
comparable magnitudes, with attendant loss of significant bits.
Compare with methods of computing sigma f(n) for n = 1 ....
infinity. If you start with n=1 (using the normally available
floating point system) you will end up with something quite
divergent from the true answer, regardless of whether the series
actually converges or not. A reasonably accurate computation
requires starting with the smallest terms.
-- "I'm a war president. I make decisions here in the Oval Office in foreign policy matters with war on my mind." - Bush. "Churchill and Bush can both be considered wartime leaders, just as Secretariat and Mr Ed were both horses." - James Rhodes.
- Next message: CBFalconer: "Re: Some Questions Asked in Interview"
- Previous message: Gordon Burditt: "Re: Format of Pointers in Unix"
- In reply to: Joe Wright: "Re: Sine code for ANSI C"
- Next in thread: P.J. Plauger: "Re: Sine code for ANSI C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|