[R] Odd results with %% and conserving memory

Bert Gunter gunter.berton at gene.com
Wed Apr 7 00:03:40 CEST 2010


Ummm... I think the "problem" is with _your_ inadequate understanding.

Consider: identical( (4.1 * 100 ) %/% 1 , 409 )

> 4.1*100 < 410
[1] TRUE

So, due to finite precision, 4.1*100 is slightly less than 410.
Whence the largest integer 1 can be divided into it is 409. i.e.

> (4.1*100) %/% 1
[1] 409

?"%/%"

Bert Gunter
Genentech Nonclinical Statistics

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of JustinNabble
Sent: Tuesday, April 06, 2010 2:27 PM
To: r-help at r-project.org
Subject: Re: [R] Odd results with %% and conserving memory


Thanks for the response. I read through the Inferno and there's a lot of
useful stuff in there. However I think you may have missed something.

Having some experience with other languages, I know that floating point
numbers aren't represented exactly, the issue is that R is off by much more
than would be expected. On my computer, cell 9,2 of (mat * 100) %% 1 is
larger than .99 and the correct result is 0. That difference seems too large
to be a problem with representing floating point numbers.

Likewise, identical( (4.1 * 100 ) %/% 1 , 409 ) returns TRUE on my computer,
so the result is off by exactly 1, too larger to be explained by floating
point error.

I think there's a problem with how the %% and %/% operators are getting
their results.
-- 
View this message in context:
http://n4.nabble.com/Odd-results-with-and-conserving-memory-tp1692845p175354
0.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at 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.



More information about the R-help mailing list