[R] integer ranges in R vs C and Java

Saptarshi Guha saptarshi.guha at gmail.com
Sat May 2 23:20:45 CEST 2009


Hello,
I'm using R-2.9 and have a question about integer ranges. On C, (OS X
platform),
LONG_MIN and LONG_MAX(from limits.h)  correspond to -2147483648(-2^31)
and 2147483647 (2^31-1)
In Java(1.4), Integer.MIN_VALUE and Integer.MAX_VALUE have the same values.

On R, as.integer(2^31-1) is the maximum (without returning NA) but the
lowest is -2147483647 (-2^31+1)

 > as.integer((-2)^31)
[1] NA

So in both Java and C can hold 2^32 different values, but R holds 2^32
-1 different values.

Have I made a mistake? Is there a reason for the difference?

Thank you
Saptarshi




More information about the R-help mailing list