[R-SIG-Mac] Unexpected behavior of R round function on Mac

peter dalgaard PDalgd at gmail.com
Fri Apr 11 11:04:09 CEST 2014


Google for "round to even", and read the Details section of ?round.


On 11 Apr 2014, at 10:42 , Per Nielsen <evilper at gmail.com> wrote:

> Hi all
> 
> I have encountered some strange/wrong behavior of the round function in R.
> 
> This is the behavior on my mac laptop:
> 
>> R.version
>               _
> platform       x86_64-apple-darwin13.0.2
> arch           x86_64
> os             darwin13.0.2
> system         x86_64, darwin13.0.2
> status
> major          3
> minor          0.2
> year           2013
> month          09
> day            25
> svn rev        63987
> language       R
> version.string R version 3.0.2 (2013-09-25)
> nickname       Frisbee Sailing
>> round(1.5)
> [1] 2
>> round(4.5)
> [1] 4
>> floor(1.5 + 0.5)
> [1] 2
>> floor(4.5 + 0.5)
> [1] 5
> 
> This is the behavior on Ubuntu 12.04 running in a virtual machine on the
> same mac:
> 
>> R.version
>               _
> platform       x86_64-pc-linux-gnu
> arch           x86_64
> os             linux-gnu
> system         x86_64, linux-gnu
> status         beta
> major          3
> minor          1.0
> year           2014
> month          03
> day            28
> svn rev        65330
> language       R
> version.string R version 3.1.0 beta (2014-03-28 r65330)
> nickname       Spring Dance
>> round(1.5)
> [1] 2
>> round(4.5)
> [1] 4
>> floor(1.5 + 0.5)
> [1] 2
>> floor(4.5 + 0.5)
> [1] 5
> 
> I would expect round(x.5) = x+1, which only happens sometimes. My colleague
> using R version 3.1.0 on Linux on a Lenovo laptop gets the expected result
> in all cases.
> 
> Is this a bug or somehow expected behavior? It seems to be related to the
> mac hardware. I can ad hoc fix it using floor, but that is hardly optimal.
> 
> Thanks,
> Per
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-SIG-Mac mailing list