[R] Why does sin(pi) not return 0?

Suzen, Mehmet msuzen at gmail.com
Thu Sep 26 14:48:52 CEST 2013


On 26 September 2013 11:30, Rainer M Krug <Rainer at krugs.de> wrote:
>>>> Why doesn't return me 0?

It isn't R question at all. You might want to read about representing
real numbers in a computer using floating point
http://en.wikipedia.org/wiki/Floating_point

If you want more precision for some reason, you may want to use Rmpfr
package from CRAN, for example
> require(Rmpfr)
> pii <- mpfr(pi, 1200)
> sin(pii)
1 'mpfr' number of precision  1200   bits
[1] 1.22464679914735317722606593227499799708305390129979194948825771626086960997325810377509325527569013655456428540074414189136673810003656057935764118217436637676835016019778833613838580470703060741630570066750947925902443295873487819032259435513861185501796412843027607796970259523768923503206248925733373776859085615900203929142965774524665617260404787862664073939e-16


> | > Is that a Fortune? And, if so, should R be using computers?

Don't blame R for real numbers.



More information about the R-help mailing list