|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Some trig trouble -- and IEEE floating point format
I too agree that the code looks good, but another (slight) possibility
occurs to me: Check the valid ranges for the Trig functions in the math
package you are using. While most packages do allow basically any value as
the input to sin(), some do place restrictions, like requiring positive
angles (id -0.5 PI radians must be converted 1.5 PI radians) or else the
input might be restricted to the domain [0,2*PI) (ie, from 0 inclusive to
2*PI NON-inclusive, so that 2*PI must be given as 0) - basically, just do a
angle_rad % 2*PI to perform the conversion there. Although in your code,
angle_rad >= 2*PI will only occur if angle_deg >= 360.
Otherwise, I'd throw in some more printf's to find the exact values for
angle_deg and angle_rad at every step to see if something you thought would
be right turns out to be wrong. I hope one of these shots in the dark
might be helpful to you.
-Jon Merz
At 05:37 PM 9/5/00 -0400, you wrote:
>In a message dated 9/5/00 2:02:53 PM Central Daylight Time,
>lionelp@worldonline.co.za writes:
>
><< double angle_rad, sine;
>
> angle_rad = angle_deg * M_PI / 180.0;
> sine = sin(angle_rad);
>
> printf("The sine of %.2f is %.8f.\r\n", angle_deg, sine);
>
> If I try to run this code, I get "Floating point error: Domain.", >>
>
>Hmmm, nothing jumps out at me, but are you sure angle_deg is a valid number?
>Basically, if you plot the sine graph (x = value, y=sin(value)) the x values
>are considered "domain" and the y values are considered "range." So, the
>numbers you feed the sin() function make up the domain, and the results you
>receive make up the range. Therefore, this error means something is wrong
>with angle_deg. Is angle_deg a double as well? How about M_PI? Usually when I
>get a Domain error, I set up the formula wrong (180/(pi*degree)) instead of
>(pi*degree)/180. But that isn't what's wrong. Check to make sure angle_deg
>isn't an integer. If it is, this should work:
>
> angle_rad = (double)angle_deg * M_PI / 180.0;
>
>Or I could be missing the error entirely.
>-Ender Wiggin
>=================================================================
>The GameProgrammer.Com mailing list is for the open discussion
>of any topic related to the art, science, and business of
>programming games. This list is especially tolerant of beginners.
>We were all beginners once
>
>To SUBSCRIBE or UNSUBSCRIBE please visit:
>http://gameprogrammer.com/mailinglist.html
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once
To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html
|
|