Consider also the following: a <- 1.2 b <- 1.0
> (a-b)%%.1 [1] 0.1 > (a-b)%/%.1 [1] 1 > .2%%.1 [1] 0 > .2%/%.1 [1] 2 This performs as described on "?%/%". In particular, the second paragraph under "Value": '%%' indicates 'x mod y' and '%/%' indicates integer division. It is guaranteed that 'x == (x %% y) + y * ( x %/% y )' (up to rounding error) unless 'y == 0' where the result is 'NA_integer_' or 'NaN' (depending on the 'typeof' of the arguments). See <URL: http://en.wikipedia.org/wiki/Modulo_operation> for the rationale. hope this helps. Spencer jim holtman wrote: > FAQ 7.31 > > a-b != 0.2 > > >> a <- 1.2 >> >> b <- 1.0 >> >> a-b-.2 >> > [1] -5.551115e-17 > > > > > On 3/31/08, Lo, Ken <[EMAIL PROTECTED]> wrote: > >> Dear all, >> >> >> >> I have come across a strange behavior of the %/% operator, and I wasn't >> sure if this was intended. >> >> >> >> i.e. >> >> a <- 1.2 >> >> b <- 1.0 >> >> (a-b) %/% 0.1 results in 1? >> >> Whereas >> >> 0.2 %/% 0.1 results in 2. >> >> >> >> Am I missing something obvious here? It seems to be consistent up to R >> 2.6.0 running in WinXP (haven't upgraded yet). >> >> >> >> Best, >> >> >> >> Ken >> >> >> >> This email message may contain legally privileged and/or confidential >> information. If you are not the intended recipient(s), or the employee or >> agent responsible for the delivery of this message to the intended >> recipient(s), you are hereby notified that any disclosure, copying, >> distribution, or use of this email message is prohibited. If you have >> received this message in error, please notify the sender immediately by >> e-mail and delete this email message from your computer. Thank you. >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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. >> >> > > > ______________________________________________ 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.