Bill Allombert on Thu, 30 Jun 2005 23:19:03 +0200

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Sin(x)

On Thu, Jun 30, 2005 at 10:16:07PM +0200, Sascha Rissel wrote:
> Thanks for all your quick help.
> I now do understand this slight difference to the expected values.
> But why do cheap pocket calculators calculate exact results of sin and cos?
> Their approximation of Pi shouldn't be more precise than that Pari provides.

It is actually slightly less precise. Since Pi is not equal to
3.141592653589793239, sin(3.141592653589793239) should not yield 0.

> Do they round the results for reasons of "usability"?

No, they simply use fixed precision.
When you ask sin(x)  with Pi/2<x<3*Pi/2 the natural thing to do is to 
substract Pi from x to move x in ]-Pi/2,Pi/2[. However, since they use
fixed precision, Pi has always the same value, so when you ask sin(Pi)
the calculator do Pi-Pi and get 0.

In PARI, the precision is not fixed, and Pi is in fact a function of the
precision.  PARI alse compute x-Pi, but to avoid the error on the value of Pi
to affect the result, it computes Pi with an higher precision that the
precision of x.  When you do sin(Pi), it computes Pi(28)-Pi(38) which is
very small but not 0.

To check that try:
? \p28
? pi28=Pi
%1 = 3.141592653589793238462643383
? \p38
   realprecision = 38 significant digits
? pi38=Pi
%2 = 3.1415926535897932384626433832795028842
? pi38-pi28
%3 = -5.04870979 E-29
? sin(pi28)
%4 = -5.04870979 E-29

However, that exhibit the main limitation with PARI real:
the precision increase only by large increment. In fact
pi38-pi28 has less than 1 bit of accuracy, but 32 bits
are returned nevertheless.

Pocket calculators also use other tricks to return better looking
results (binary-coded decimals, guard digits), but they should not
come into play here.