Prof Brian Ripley wrote:

I've now found a Windows system that does this. This is also Windows XP, fully patched, and with the same rw2010. So it may be chip-specific: the one that works is a P4 and the one that does not is a latest Pentium M.

I am not sure that the guarantee on the help page has been supported for a while. I've altered the code so it is more likely to be.

BTW,

options(digits=20)
1 %% 0.001

[1] 0.0009999999999999792

shows why the original is not a bug in R.

Why is that not a bug in R? On my machine (windows XP, rw2010 from CRAN) I get:

test <- function(x, y) (x %% y) + y * ( x %/% y ) # should be x
> test(1, 0.001)
[1] 1.001
> test(1, 0.1)
[1] 1.1
> test(1, 1)
[1] 1
> test(1, 0.01)
[1] 1.01

and this differences (well, not the third one) cannot be said to be rounding
error.


Kjetil


On Thu, 12 May 2005 [EMAIL PROTECTED] wrote:

On Wed, 11 May 2005 [EMAIL PROTECTED] wrote:

Yes, you are correct. I had only checked one of my platforms. Linux
works as you suggest. But for me on Windows,

x <- 1
y <- 0.2
x %/% y

[1] 5 ## I get a 4 in Linux


I get 5 on Windows, but

(x %% y) + y * (x %/% y)

[1] 1

so is there a problem particular to your Windows runtime?



version _ =20 platform i386-pc-mingw32 arch i386 =20 os mingw32 =20 system i386, mingw32 =20 status =20 major 2 =20 minor 1.0 =20 year 2005 =20 month 04 =20 day 18 =20 language R =20


-----Original Message----- From: Peter Dalgaard [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 11, 2005 4:14 PM To: McGehee, Robert Cc: [EMAIL PROTECTED]; Peter Dalgaard; [EMAIL PROTECTED]; [EMAIL PROTECTED]; r-devel@stat.math.ethz.ch Subject: Re: [Rd] bug in modulus operator %% (PR#7852)


"McGehee, Robert" <[EMAIL PROTECTED]> writes:

Yes, but from ?"%%":
"It is guaranteed that 'x =3D=3D (x %% y) + y * (x %/% y)' (up to =

rounding

error) ..."
=20
(R 2.1.0)

x <- 1
y <- 0.2
x %% y

[1] 0.2

(x %% y) + y * (x %/% y)

[1] 1.2 =20 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?





--

Kjetil Halvorsen.

Peace is the most effective weapon of mass construction.
              --  Mahdi Elmandjra




-- No virus found in this outgoing message. Checked by AVG Anti-Virus.

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to