[R] Odd results with %% and conserving memory

Steve Lianoglou mailinglist.honeypot at gmail.com
Wed Apr 7 00:09:30 CEST 2010


Hi,

On Tue, Apr 6, 2010 at 5:26 PM, JustinNabble <justinmmcgrath at hotmail.com> wrote:
>
> 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.

Like which languages?

python> 4.1 * 100
409.99999999999994

scala> 4.1 * 100
res0: Double = 409.99999999999994

ruby> 4.1 * 100 < 410
=> true

matlab> 4.1 * 100 < 410

ans =

     1

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the R-help mailing list