"Michael S. Davis" wrote:
> I use MathLib for Trig functions.  Sin and Tan seem to work fine.  But
> Cos has a quirk.  cos(0)=1 but cos(90)=2.8328e-16.  Now I know that is
> headed toward zero but it's not zero.  I have looked at many Palm
> calculator applications and find that this is consistent on every calc
> that I have tested.  One reports cos(90) as 6.123e-17 another 2.8328e-16
> one with 8.9e-15.  I did find one that reported zero.

This is a problem in MathLib.  Most implementations of trig functions
have a similar problem when the argument is outside the "canonical"
range.  Sin and tan have the same problem as cos with certain arguments;
try sin(180) for example, or tan(180).  Unc
(http://www.flash.net/~marknu/unc) is one calculator that does not have
this problem.  What I do is normalize the argument of sin and tan so it
falls within the canonical range of -90 to +90 degrees.  Cos(x) is just
calculated as sin(90-x).

Understand, however, that this isn't really a bug in MathLib.  All trig
calculations have a certain intrinsic error due to the nature of
floating point arithmetic.  MathLib's result for cos(10) is just as
"incorrect" as cos(90).  It's just that we humans can recognize a number
that's slightly different from zero more easily than a number that's
slightly different from 0.984807753012208.
--Mark

Reply via email to