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

David Smith david at revolutionanalytics.com
Tue Jun 19 00:35:06 CEST 2012


This is standard behaviour for a floating-point computational system
like R. You might like to take a look at this blog post for a
backgrounder on floating-point arithmetic in R.

http://blog.revolutionanalytics.com/2009/03/when-is-a-zero-not-a-zero.html

# David Smith

On Mon, Jun 18, 2012 at 2:26 PM, whf1984911 <whf1984911 at yahoo.com.cn> 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
>
> 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.
>
> How could get around this, any suggestions?
>
> Thanks,
> Haifeng Wu
> Graduate Student
> University of South Carolina

--
David M Smith <david at revolutionanalytics.com>
VP of Marketing, Revolution Analytics  http://blog.revolutionanalytics.com
Tel: +1 (650) 646-9523 (Palo Alto, CA, USA)
Twitter: @revodavid



More information about the R-help mailing list