2

Context

R's help() function indicates that round() adheres to a standard that is identical to IEEE 754: round halves to even.

Wikipedia describes this standard with the following example: 23.5 becomes 24 and 24.5 becomes 24.

help() also states, ...this is dependent on OS services and on representation error.

Experiment

System details

  • R version: 3.6.2 (2019-12-12)
  • Arch / OS: x86_64, darwin18.7.0 (MacOS)

On my machine, I see that

round(0.55, digits = 1)  # [1] 0.6
round(1.55, digits = 1)  # [1] 1.6
round(2.55, digits = 1)  # [1] 2.5
round(3.55, digits = 1)  # [1] 3.5

Question

Should I attribute the discrepancy between the first two and second two statements as errant OS services and or representation error?

Tantillo
  • 367
  • 1
  • 5
  • 1
    See the edit. Without `digits = 1` it rounds to integer. Also, what are the OS and version of R? – Rui Barradas Feb 02 '20 at 18:06
  • I suspect `2.55` is stored in IEEE double, hence would not be exactly 2.55, but instead apparently `2.5499999999...((plus garbage))`. Hence it is correctly rounding "down". – Rick James Feb 08 '20 at 02:20

0 Answers0