[R] Mismatch in logical result?
Bernardo Rangel Tura
tura at centroin.com.br
Sat Nov 8 08:37:02 CET 2008
On Fri, 2008-11-07 at 15:53 +0530, Shubha Vishwanath Karanth wrote:
>
> Hi R,
>
>
>
> I have certain checkings, which gives FALSE, but actually it is true. Why does this happen? Note that the equations that I am checking below are not even the case of recurring decimals...
>
>
>
> > 1.4^2 == 1.96
>
> [1] FALSE
>
>
>
> > 1.2^3==1.728
>
> [1] FALSE
Shubha
the correct answer for us is TRUE for the computer is FALSE
1.4^2-1.96
[1] -2.220446e-16
1.2^3-1.728
[1] -2.220446e-16
but if you use "all.equal"
all.equal(1.4^2,1.96)
[1] TRUE
all.equal(1.2^3,1.728)
[1] TRUE
More details in R FAQ 7.31
--
[]s
Tura
More information about the R-help
mailing list