[R] Newbie question on precision

(Ted Harding) Ted.Harding at manchester.ac.uk
Fri Jan 8 18:39:51 CET 2010


On 08-Jan-10 16:56:25, Paul Evans wrote:
> Hi all,
> How can I get R to change the default precision value? For example:
>> x=0.99999999999999999
>> 1-x
> [1] 0
> 
> Is there a way that I can get a non-zero value using some parameter,
> or some package?
> many thanks.

The problem here is that, as far as R in concerned, once you have entered
  x=0.99999999999999999
then x is *exactly* 1. Namely, your x is 1 - 1e-17, and the two things
you need to take note of are:

  .Machine$double.eps
  # [1] 2.220446e-16
  .Machine$double.neg.eps
  # [1] 1.110223e-16

and the descriptions in ?.Machine which say:

  "double.eps: the smallest positive floating-point number 'x'
   such that '1 + x != 1'."

  "double.neg.eps: a small positive floating-point number 'x'
   such that '1 - x != 1'. "

Both of these (in particular "double.neg.eps") are greater
than 1e-17, so your x was stored as 0.

I believe there may be packages which can work to greater precision,
but I have to leave it to others to describe them (if any).

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 08-Jan-10                                       Time: 17:39:47
------------------------------ XFMail ------------------------------



More information about the R-help mailing list