[R] (1-1e-100)==1 true?

Petr Savicky savicky at cs.cas.cz
Tue Jun 19 07:01:51 CEST 2012


On Mon, Jun 18, 2012 at 02:26:41PM -0700, whf1984911 wrote:
> Hi, 
> 
> This problems has bothered me for the lase couple of hours.  
> 
> > 1e-100==0
> [1] FALSE
> > (1-1e-100)==1
> [1] TRUE
> 
> How can I tell R that 1-1e-100 does not equal to 1,  actually, I found out
> that
>  > (1-1e-16)==1
> [1] FALSE
> > (1-1e-17)==1
> [1] TRUE

Hi.

The smallest eps, such that 1 - eps is not equal 1 in computer arithmetic
(double precision) is 2^-53, since the numbers are represented with 53 bits
precision.

  1 - 2^-53 == 1
  [1] FALSE

> The reason I care about this is that I was try to use qnorm() in my code,
> for example,
> 
> > qnorm(1e-100)
> [1] -21.27345
> 
> and if I want to find qnorm(x) where x is very close to 1, say x=1-1e-100, 
> then you would think using
> qnorm(1-x, lower.tail=F) would give me something other than INF, but that
> does not work since R would recognize x==1 in this case and therefore,
> 1-x==0, so qnorm(1-x, lower.tail=F) will give me INF which is what I try to
> avoid in my code.

Function qnorm(x) satisfies the identity qnorm(x) = - qnorm(1-x). So,
-qnorm(1e-100) may be used instead of qnorm(1-1e-100).

Hope this helps.

Petr Savicky.



More information about the R-help mailing list