renjin
renjin copied to clipboard
Casting from double to integer does not handle overflow correctly
As noticed by @kalibera, overflow during conversion from double to integer is not handled correctly.
Most basically, the expression as.integer(2^40)
should overflow to NA
, not the integer max value.
In cases where double-precision values are used as indices, it gets more complicated. For example, in the code below:
a <- as.numeric(1:1000000)
c <- a[c(-1*sum(a), sum(a))]
Both -1 * sum(a)
and sum(a)
would overflow to NA
when cast to 32-bit integers, but is still within the range of a 64-bit integer, and so in GNU R, this leads to
Error in a[c(-1 * sum(a), sum(a))] :
only 0's may be mixed with negative subscripts
whereas Renjin returns
[1] NA NA