Re: Trigonometric Problem, Particularly tan() Function
Re: Trigonometric Problem, Particularly tan() Function
- Subject: Re: Trigonometric Problem, Particularly tan() Function
- From: "Michael Ash" <email@hidden>
- Date: Sun, 13 Jul 2008 00:54:45 -0400
On Sun, Jul 13, 2008 at 12:43 AM, Patrick Walker
<email@hidden> wrote:
> Yes, I'm aware that you need to supply radians.
>
> Everthing appears to be fine when going from 0 to 45 degrees but at 90
> degrees, the tangent returns -22877334.
>
> I've even tried doing the tan(x) = sin(x) / cos(x) approach.
Floating point arithmetic is inherently imprecise.
Atan(-22877334) is equal to pi/2 to within roughly eight decimal
places or approximately 25 bits. I'm not sure what the guaranteed
accuracy of that function is supposed to be, and this does seem to be
a bit excessive, but on the other hand you are right next to a
singularity in the function. Depending on how you're generating "90
degrees", that could be introducing further inaccuracy.
These aren't mathematically ideal functions, so you can't expect them
to behave as such. This goes particularly when using them in a region
of extreme behavior such as this.
In particular you should never expect a function which is undefined or
infinite at a single point and defined and finite in all the regions
immediately adjacent to that point to produce an undefined or infinite
result, unless that point is a value which can be represented
precisely, such as "0". 90 degrees cannot be represented precisely
when converted to radians, so you'll never get NaN or INFINITY out of
the tan() function.
If you still think they're misbehaving, I suggest posting the code
you're using. It's difficult to provide more specific help with no
code.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden