set.seed(1); x <- sort(rcauchy(10))
x3 <- round2(x, 3)
x3 == round2(x, 3) # Supposed to be reliable (all TRUE)
rbind(x, x3) # Comparison
(x3[1] * 2^(0:9)) / 2^(0:9)
print((x3[1] * 2^(0:11)), digits = 14)
# Round to approx 1 d.p.
x1 <- round2(x, 1)
x1 == round2(x, 1) # Supposed to be reliable (all TRUE)
rbind(x, x1)
x1[8] == 0.75 # 3/4
print((x1[1] * 2^(0:11)), digits = 9)
seq(31) / 32
Run the code above in your browser using DataLab