0

Should bitw* function use round to coerce to integer rather than as.integer?

str((6.6-6)*10)
#num 6
bitwShiftL(1,(6.6-6)*10)
#[1] 32
bitwShiftL(1,6)
#[1] 64

This is due to the fact that Bitwise Logical Operations coerce to integer and as.integer does trunc. In our case (6.6-6)*10 is internally stored as 5.99999... which is ok (see Why are these numbers not equal?)

I would assume that someone writing bitwShiftL(1,5.9) is actually willing to shift by 6 rather than 5.

Community
  • 1
  • 1
Battmanux
  • 61
  • 2
  • 2
    Coercing float to int means flooring (i.e., cutting the mantisse) in any programming language I know. So one should not change this paradigm in R... – Patrick Roocks Sep 01 '16 at 08:47
  • ok for float to int conversion, bit wouldn't it be better to round the argument within bitwShift[R|L] instead of coercing to int? It seems that I am not the only one who had shifted by 5 when I was expecting to shift by 6. – Battmanux Sep 01 '16 at 12:28

0 Answers0