[Rd] bug in modulus operator %% (PR#7852)

p.dalgaard at biostat.ku.dk p.dalgaard at biostat.ku.dk
Wed May 11 22:14:17 CEST 2005


"McGehee, Robert" <Robert.McGehee at geodecapital.com> writes:

> Yes, but from ?"%%":
> "It is guaranteed that 'x == (x %% y) + y * (x %/% y)' (up to rounding
> error) ..."
> 
> (R 2.1.0)
> > x <- 1
> > y <- 0.2
> > x %% y
> [1] 0.2
> > (x %% y) + y * (x %/% y)
> [1] 1.2
> 
> Certainly 1 does not equal 1.2 as the documentation would suggest, and
> these seem like large enough numbers to not be effected by rounding
> errors or lack of precision.

Now that looks a bit odd, but it isn't universal:

> x <- 1
> y <- 0.2
> x %% y
[1] 0.2
> x %/% y
[1] 4
> (x %% y) + y * (x %/% y)
[1] 1

So what platform was that happening on?

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-devel mailing list