jan.hattendorf at unibas.ch
2009-Aug-01  20:05 UTC
[Rd] incorrect result (41/10-1/10)%%1 (PR#13863)
Full_Name: jan hattendorf
Version: 2.9.0
OS: XP
Submission from: (NULL) (213.3.108.185)
I get an incorrect result for
(41/10-1/10)%%1
[1] 1
The error did not occur with other numbers than 41 (1, 11, 21, 31, 51, ...)
test <- rep(NA, 1000)
for(i in 1:1000){
  test[i] <- i/10-1/10
}
test[test%%1==0]
jan.hattendorf at unibas.ch wrote:> Full_Name: jan hattendorf > Version: 2.9.0 > OS: XP > Submission from: (NULL) (213.3.108.185) > > > I get an incorrect result for > > (41/10-1/10)%%1 > > [1] 1 > > The error did not occur with other numbers than 41 (1, 11, 21, 31, 51, ...) > > > test <- rep(NA, 1000) > for(i in 1:1000){ > test[i] <- i/10-1/10 > } > test[test%%1==0] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-develFAQ 7.31 -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Good morning Jan, Could this be covered off by the following? http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f Kind regards, Sean On Sat, Aug 1, 2009 at 9:05 PM, <jan.hattendorf at unibas.ch> wrote:> Full_Name: jan hattendorf > Version: 2.9.0 > OS: XP > Submission from: (NULL) (213.3.108.185) > > > I get an incorrect result for > > (41/10-1/10)%%1 > > [1] 1 > > The error did not occur with other numbers than 41 (1, 11, 21, 31, 51, ...) > > > test <- rep(NA, 1000) > for(i in 1:1000){ > ?test[i] <- i/10-1/10 > } > test[test%%1==0] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Not a bug, just a FAQ (7.31). http://CRAN.R-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f On Sat, 1 Aug 2009, jan.hattendorf at unibas.ch wrote:> Full_Name: jan hattendorf > Version: 2.9.0 > OS: XP > Submission from: (NULL) (213.3.108.185) > > > I get an incorrect result for > > (41/10-1/10)%%1 > > [1] 1 > > The error did not occur with other numbers than 41 (1, 11, 21, 31, 51, ...) > > > test <- rep(NA, 1000) > for(i in 1:1000){ > test[i] <- i/10-1/10 > } > test[test%%1==0] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >
This is not a bug. It is a case of R FAQ 7.34:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-the
se-numbers-are-equal_003f 
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: r-devel-bounces at r-project.org
[mailto:r-devel-bounces at r-project.org] Namens jan.hattendorf at unibas.ch
Verzonden: zaterdag 1 augustus 2009 22:05
Aan: r-devel at stat.math.ethz.ch
CC: R-bugs at r-project.org
Onderwerp: [Rd] incorrect result (41/10-1/10)%%1 (PR#13863)
Full_Name: jan hattendorf
Version: 2.9.0
OS: XP
Submission from: (NULL) (213.3.108.185)
I get an incorrect result for
(41/10-1/10)%%1
[1] 1
The error did not occur with other numbers than 41 (1, 11, 21, 31, 51,
...)
test <- rep(NA, 1000)
for(i in 1:1000){
  test[i] <- i/10-1/10
}
test[test%%1==0]
______________________________________________
R-devel at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.
> I get an incorrect result for > > (41/10-1/10)%%1 > > [1] 1Note that due to rounding errors, 41/10-1/10 is formatC(41/10-1/10, digits=20) # [1] "3.9999999999999995559" Besides FAQ 7.31, related information may be found also at http://wiki.r-project.org/rwiki/doku.php?id=misc:r_accuracy Petr.