Try this: 0.7-0.3==0.4 (We get FALSE) 0.7-0.3<0.4 (We get TRUE) but 0.8-0.3==0.5 (TRUE) 0.8-0.3<0.5 (FALSE) Funny, he? There is a way around: round(0.7-0.3,1)==0.4 (TRUE) Obviously there is a problem with some combinations of decimal subtractions, that - we have the feeling - shouldt be solved. Best regards Sven & Wolfgang -- View this message in context: http://www.nabble.com/bug-when-subtracting-decimals--tp23136337p23136337.html Sent from the R help mailing list archive at Nabble.com.
This is a FAQ. Try this: all.equal(0.7-0.3, 0.4) On Mon, Apr 20, 2009 at 10:07 AM, wolfgang.siewert < wolfgang.siewert@gmail.com> wrote:> > Try this: > > 0.7-0.3==0.4 > (We get FALSE) > 0.7-0.3<0.4 > (We get TRUE) > > but > 0.8-0.3==0.5 > (TRUE) > 0.8-0.3<0.5 > (FALSE) > > Funny, he? > > There is a way around: > round(0.7-0.3,1)==0.4 > (TRUE) > > Obviously there is a problem with some combinations of decimal > subtractions, > that - we have the feeling - shouldt be solved. > > Best regards > Sven & Wolfgang > -- > View this message in context: > http://www.nabble.com/bug-when-subtracting-decimals--tp23136337p23136337.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
this is a (very) Frequently Asked Question; check: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f Best, Dimitris wolfgang.siewert wrote:> Try this: > > 0.7-0.3==0.4 > (We get FALSE) > 0.7-0.3<0.4 > (We get TRUE) > > but > 0.8-0.3==0.5 > (TRUE) > 0.8-0.3<0.5 > (FALSE) > > Funny, he? > > There is a way around: > round(0.7-0.3,1)==0.4 > (TRUE) > > Obviously there is a problem with some combinations of decimal subtractions, > that - we have the feeling - shouldt be solved. > > Best regards > Sven & Wolfgang-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
wolfgang.siewert <wolfgang.siewert <at> gmail.com> writes:> There is a way around: > round(0.7-0.3,1)==0.4 > (TRUE) > > Obviously there is a problem with some combinations of decimal subtractions, > that - we have the feeling - shouldt be solved.Oh no, not that one again! This was lecture two in my first computer course in 1968, but it seems to be gone the way of the dodo since than. Dietr
Dieter Menne wrote:> wolfgang.siewert <wolfgang.siewert <at> gmail.com> writes: > >> There is a way around: >> round(0.7-0.3,1)==0.4 >> (TRUE) >> >> Obviously there is a problem with some combinations of decimal subtractions, >> that - we have the feeling - shouldt be solved. > > Oh no, not that one again! This was lecture two in my first computer > course in 1968, but it seems to be gone the way of the dodo since than.What makes you think that the average useR has had any exposure to computer science courses? ;-) I bemoan the apparent inability of those asking such questions to use the resources provided to solve these problems for themselves... Gavin> > Dietr > > ______________________________________________ > 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.
Hi, Gavin Simpson wrote:> > I bemoan the apparent inability of those asking such questions to use > the resources provided to solve these problems for themselves...Looking at all the people who quite obviously do NOT "read the posting guide and provide commented, minimal, self-contained, reproducible code", I wonder whether the mailing list could be configured to reply to each new mail (not replies in a thread) with an automated mail like this: "Have you read the posting guide and the FAQs? If you do not get a reply within two days, you may want to look at both and think about reformulating your query. Oh, and while you are at it, look through the archives, a lot of questions have already been asked and answered before." Just a thought, Stephan
Hi r-help-bounces at r-project.org napsal dne 20.04.2009 19:01:46:> wolfgang.siewert <wolfgang.siewert <at> gmail.com> writes: > > > There is a way around: > > round(0.7-0.3,1)==0.4 > > (TRUE) > > > > Obviously there is a problem with some combinations of decimalsubtractions,> > that - we have the feeling - shouldt be solved. > > Oh no, not that one again! This was lecture two in my first computer > course in 1968, but it seems to be gone the way of the dodo since than.Maybe that is because of Excel is so widespread now and gives expected results (it probably silently rounds all decimal numbers before calculation). Regards Petr> > Dietr > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
A quarter-century ago I was part of the IEEE 854 group that tried to suggest a radix free arithmetic standard. One of the interests was decimal arithmetic. I actually have owned 2 decimal arithmetic computers, a North Star Horizon (with decimal hardware I had to build by hand from a kit) and a Radio Shack TRS80 Model 100, which used software BCD arithmetic. Interestingly, the same h/w for the TRS80 by NEC used binary FP. With the number of times the question of arithmetic coming up on this list, one wonders if a decimal arithmetic version of R, or other software too, might not be worthwhile. There are other issues that arise, of course, but binary floating point does upset folk used to working in base 10, and the I/O conversions do make things look messy. JN
> "Have you read the posting guide and the FAQs? If you do not get a reply > within two days, you may want to look at both and think about reformulating > your query. Oh, and while you are at it, look through the archives, a lot of > questions have already been asked and answered before."As I say every time someone brings this up, there are currently ~130 printed pages of FAQs. Reading all that seems a rather large burden on the novice poster. Hadley -- http://had.co.nz/