[R] normal distribution and floating point traps (?): unexpected behavior
Duncan Murdoch
murdoch.duncan at gmail.com
Wed Mar 30 02:40:16 CEST 2011
On 29/03/2011 5:33 PM, Patrizio Frederic wrote:
> dear all,
> here's a couple of questions that puzzled me in these last hours:
>
> ##### issue 1 qnorm(1-10e-100)!=qnorm(10e-100)
>
> qnorm(1-1e-10) == -qnorm(1e-10)
>
> # turns on to be FALSE. Ok I'm not a computer scientist but,
> # but I had a look at the R inferno so I write:
>
> all.equal(qnorm(1-1e-10) , -qnorm(1e-10))
>
> # which turns TRUE, as one would expect, but
>
> all.equal(qnorm(1-1e-100) , -qnorm(1e-100))
>
> # turns FALSE: Indeed
>
> # qnorm(1e-100) is -21.27345, and
> # qnorm(1-1e-100) is Inf
Since
1 - 1e-100 == 1
is TRUE, but
1e-100 == 0
is FALSE, this is not a surprise.
Duncan Murdoch
More information about the R-help
mailing list