[R] Mismatch in logical result?

2008-11-07 Thread Shubha Vishwanath Karanth
 

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

 

 

Thanks in advance, Shubha

Shubha Karanth | Amba Research

Ph +91 80 3980 8031 | Mob +91 94 4886 4510 

Bangalore * Colombo * London * New York * San José * Singapore * 
www.ambaresearch.com

 

This e-mail may contain confidential and/or privileged i...{{dropped:13}}

__
R-help@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.


Re: [R] Mismatch in logical result?

2008-11-07 Thread Heinz Tuechler

Maybe this?
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

At 11:23 07.11.2008, Shubha Vishwanath Karanth wrote:

Content-Type: text/plain
Content-Disposition: inline
Content-length: 569



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





Thanks in advance, Shubha

Shubha Karanth | Amba Research

Ph +91 80 3980 8031 | Mob +91 94 4886 4510

Bangalore * Colombo * London * New York * San 
José * Singapore * www.ambaresearch.com




This e-mail may contain confidential and/or privileged i...{{dropped:13}}


__
R-help@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.


__
R-help@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.


Re: [R] Mismatch in logical result?

2008-11-07 Thread Bernardo Rangel Tura
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@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.