On Sun, Jul 13, 2008 at 9:30 AM, Patrick Walker <[EMAIL PROTECTED]> wrote: > I can't post the whole thing because it's sort of large and "integrated" but > here is what I have originally done. > > float radians; > > radians = ([entryField floatValue] * M_PI / 180); > [outField setFloatValue:tan(radians)];
Floats have 23 bits of accuracy. As I stated earlier, your result is accurate to roughly 25 bits. I think this is rather better than you should dream to hope for. > A simple solution could involve using another trigonometgric implementation > available to Xcode. The question is are there any other than the numerical > method "math.h" versions? That's not so bad because I can simply trap +- > 90 and +-270 angles but I am trying to get as much speed. Your result is more accurate than you deserve to have. Switching to another implementation is not going to solve the fundamental problem that you're using numbers that are inherently inaccurate. You're already as close as you're going to get with floats. > My other problems seems to be -2877334 itself. To me, that appears to be a > rather strange value for a floating point number, esp. when cos(pi/2) is > returning near-zero (an "e-08") number as well. I don't understand what's so strange about it. The limit of tan(x) as x approaches pi/2 from the right is negative infinity. Thus you would expect to get very large negative numbers if you are close to pi/2 but slightly beyond it. Which is exactly what you're giving it and exactly what you're getting. To repeat myself, floating point numbers are inherently inaccurate. They aren't perfect mathematical functions. The functions themselves, and the numbers going into them, are approximations. Your result is already perfectly accurate to the limit of the data type you're using. If you can state why this result is bad and what behavior you require, maybe we can suggest how to obtain it. If you just need pi/2 to produce NaN or INFINITY, you'll need to decide how much slop on either side you're willing to accept, then manually check for that value with that much slop. Mike _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]