Dear all, Could someone please explain the following perculiarity? > 2 == 0.2/0.1 [1] TRUE > 3 == 0.3/0.1 [1] FALSE Similarly, floor(0.2/0.1) = 2 floor(0.3/0.1) = 2 Thank you, Simon
On 8/9/05 7:42 AM, "Simon Woodhead" <simon.woodhead at bristol.ac.uk> wrote:> Dear all, > > Could someone please explain the following perculiarity? > >> 2 == 0.2/0.1 > [1] TRUE >> 3 == 0.3/0.1 > [1] FALSE > > Similarly, > > floor(0.2/0.1) = 2 > floor(0.3/0.1) = 2This is a FAQ (http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these- numbers-are-equal_003f) Hope this helps. Sean
Simon Woodhead wrote:> Dear all, > > Could someone please explain the following perculiarity?Please read the FAQ "Why doesn't R think these numbers are equal" (as the posting gude asks you to do). Uwe Ligges> > 2 == 0.2/0.1 > [1] TRUE > > 3 == 0.3/0.1 > [1] FALSE > > Similarly, > > floor(0.2/0.1) = 2 > floor(0.3/0.1) = 2 > > Thank you, > Simon > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Look at ?Comparison, especially in the "Note" section, i.e., 3 == 0.3/0.1 identical(all.equal(3, 0.3/0.1), TRUE) Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Simon Woodhead" <simon.woodhead at bristol.ac.uk> To: <r-help at stat.math.ethz.ch> Sent: Tuesday, August 09, 2005 1:42 PM Subject: [R] floor() rounding problem?> Dear all, > > Could someone please explain the following perculiarity? > > > 2 == 0.2/0.1 > [1] TRUE > > 3 == 0.3/0.1 > [1] FALSE > > Similarly, > > floor(0.2/0.1) = 2 > floor(0.3/0.1) = 2 > > Thank you, > Simon > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >