[R] numeric equality
Yu, Changhong
YuC at ccf.org
Wed Mar 18 17:59:54 CET 2009
Thanks very much.
-----Original Message-----
From: David M Smith [mailto:david at revolution-computing.com]
Sent: Wednesday, March 18, 2009 12:55 PM
To: Yu, Changhong
Cc: r-help at r-project.org
Subject: Re: [R] numeric equality
On Wed, Mar 18, 2009 at 8:58 AM, Yu, Changhong <YuC at ccf.org> wrote:
> Dear all,
> I am totally confused by the following R output, but don't have a clue
> for it.
>
>> a <- 1 - 0.2
>
>> a == 0.8
>
> [1] TRUE
>
>> a <- 1 - 0.8
>
>> a == 0.2
>
> [1] FALSE
This is expected behaviour. The bottom line is that you shouldn't
rely on the equality operator when dealing with floating point values
in any numerical software, including R.
I write about this in detail at:
http://blog.revolution-computing.com/2009/03/when-is-a-zero-not-a-zero.h
tml
which will hopefully clear up your questions.
# David Smith
--
David M Smith <david at revolution-computing.com>
Director of Community, REvolution Computing www.revolution-computing.com
Tel: +1 (206) 577-4778 x3203 (Seattle, USA)
Check out our upcoming events schedule at
www.revolution-computing.com/events
===================================
P Please consider the environment before printing this e-mail
Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2008).
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.
Confidentiality Note: This message is intended for use\...{{dropped:13}}
More information about the R-help
mailing list