On Thu, Sep 06, 2012 at 02:45:20PM -0700, Shayne Hodge wrote: > I accidentally posted the wrong version of my code, omitting the Q1 loop, > and, sure enough that loop generates non-integers: > > qfracseq <- seq(from = 1, to = 0, by = -.1) > Q <- 10 > Qseq <- Q*qfracseq > > > Qseq [1] 10.00000000000000000 9.00000000000000000 8.00000000000000000 > > 7.00000000000000000 > [5] 6.00000000000000000 5.00000000000000000 3.99999999999999911 > 2.99999999999999911 > [9] 1.99999999999999956 0.99999999999999978 0.00000000000000000 > > > ----- > > I'm a tad puzzled by why my code would do this; is this a result of some > base-10 fractions not representing as cleanly in base-2 as in -10?
Hi. Yes. For example, 0.2 in base 10 is 0.00110011001100110011001100110011... in base 2. See FAQ 7.31 and http://rwiki.sciviews.org/doku.php?id=misc:r_accuracy for further examples and some hints. Hope this helps. Petr Savicky. ______________________________________________ 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.