[R] round giving different results on Windows and Mac

Ruth Ripley ruth at stats.ox.ac.uk
Sat Mar 10 15:51:20 CET 2012


Duncan,

Thanks for your reply: given Petr's response, it seems the problem is 
the interpretation by the printing code, not the actual representation 
of the number. Given the representation, 1.817 would be correct, unless 
at the working accuracy it is considered to be equal to 1.8165 (as 
indeed I asked it to be).

I will have to find a workaround, or live with two sets of test results.

Ruth

On 10/03/2012 00:48, Duncan Murdoch wrote:
> On 12-03-09 4:34 PM, Ruth Ripley wrote:
>> Dear all,
>>
>> I have been running some tests of my package RSiena on different
>> platforms and trying to reconcile the results.
>>
>> With Mac, the commands
>>
>> options(digits=4)
>> round(1.81652, digits=4)
>>
>> print 1.817
>
> The value you're printing is 1.8165, so I believe Windows gets it right
> using our "round-to-even" rule, but I'm not surprised that there are
> differences. The value 1.8165 isn't exactly representable, so it's
> somewhat random whether a system chooses to represent it slightly larger
> or slightly smaller.
>
> Duncan Murdoch
>
>
>>
>> With Windows, the same commands print 1.816
>>
>> I am not bothered which answer I get, but it would be nice if they were
>> the same. A linux box agreed with the Mac.
>>
>> Mac sessionInfo():
>> R version 2.14.2 (2012-02-29)
>> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>>
>> locale:
>> [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
>>
>> attached base packages:
>> [1] stats graphics grDevices utils datasets methods base
>>
>> other attached packages:
>> [1] RSiena_1.0.12.205
>>
>> loaded via a namespace (and not attached):
>> [1] grid_2.14.2 lattice_0.20-0 Matrix_1.0-4 tools_2.14.2
>>
>> Windows (but 2.14.1patched was the same) sessionInfo():
>> R version 2.15.0 alpha (2012-03-08 r58640)
>> Platform: i386-pc-mingw32/i386 (32-bit)
>>
>> locale:
>> [1] LC_COLLATE=English_United Kingdom.1252
>> [2] LC_CTYPE=English_United Kingdom.1252
>> [3] LC_MONETARY=English_United Kingdom.1252
>> [4] LC_NUMERIC=C
>> [5] LC_TIME=English_United Kingdom.1252
>>
>> attached base packages:
>> [1] stats graphics grDevices utils datasets methods base
>>
>> Any enlightenment would be gratefully received.
>>
>> Ruth
>

-- 
Ruth M. Ripley,                         Email:ruth at stats.ox.ac.uk
Dept. of Statistics,                    http://www.stats.ox.ac.uk/~ruth/
University of Oxford,                   Tel:   01865 282857
1 South Parks Road, Oxford OX1 3TG, UK  Fax:   01865 272595



More information about the R-help mailing list