Re: [R] Mismatch in logical result?

From: Bernardo Rangel Tura <tura_at_centroin.com.br>
Date: Sat, 08 Nov 2008 05:37:02 -0200

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 08 Nov 2008 - 07:46:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 08 Nov 2008 - 10:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive