[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sine and cosine functions
From: |
Ben Abbott |
Subject: |
Re: Sine and cosine functions |
Date: |
Thu, 02 May 2013 23:02:02 +0800 |
On May 2, 2013, at 7:55 AM, André Pereira wrote:
> Good evening
>
> I installed Octave today, and I came by a problem:
> If I ask for the value of cos(pi) it returns -1, however if I ask for the
> value of sin(pi) it returns a value with an order of magnitude of -17.
> Obviously, sin(pi) is 0. Although the value returned is of insignificant
> magnitude, the fact is, it is not 0. In fact, if I ask for the cosine or the
> sine of pi/2 it will not return 0 nor 1.
>
> Rounding the values would be a logical way to solve this, but I reckon it
> might cause some problems with other angle values.
>
> So what I wanted to ask you is if this is a problem that arises because of
> the limited digits the computer is allowed to use or if there is some way to
> work around this without compromising the accuracy of other calculations.
>
> Thank you
> André Pereira
Yeah, its due to the limited number of digits. "pi" isn't rational and using
double precision is only accurate to 16 digits. Thus, it is expected that
sin(pi) would produce an error on the order of 10^-17 to 10^-16.
Ben