[R] modulo operation

"José M. Blanco Moreno" jmblanco at ub.edu
Thu Sep 9 14:56:15 CEST 2010


>> Did you read the documentation before you read the code?
>>
>> ‘%%’ and ‘x %/% y’ can be used for non-integer ‘y’, e.g. ‘1 %/%
>> 0.2’, but the results are subject to rounding error and so may be
>> platform-dependent. Because the IEC 60059 representation of ‘0.2’
>> is a binary fraction slightly larger than ‘0.2’, the answer to ‘1
>> %/% 0.2’ should be ‘4’ but most platforms give ‘5’.
>>
>> I suspect that is relevant to your interests....
>>
>
> Yes. I think José is assuming that 25 %/% 0.2 and floor(25/0.2) are 
> equal, but they are not, because rounding affects them differently. 
> (The first is a single operation with no rounding except in the 
> representation of 0.2; the second is two operations and is subject to 
> another set of rounding.)
>
> Duncan Murdoch
Thank you (both) very much for the info. Indeed I wasn't aware of that 
piece of documentation and of the implications of rounding. Excuse me 
for my hasty question when facing this behaviour.

-- 
---------------------------------------
José M. Blanco-Moreno

Dept. de Biologia Vegetal (Botànica)
Facultat de Biologia
Universitat de Barcelona
Av. Diagonal 645
08028 Barcelona
SPAIN
---------------------------------------

phone: (+34) 934 039 863
fax: (+34) 934 112 842



More information about the R-help mailing list