[R] Max value of an integer
Mikko Korpela
mikko.korpela at aalto.fi
Wed Jan 11 13:45:23 CET 2012
On 01/11/2012 12:01 PM, Rui Esteves wrote:
> Is there any constant that represents the maximum value of an integer?
Yes, there is (assuming you refer to the 'integer' type). See ?.Machine.
> .Machine$integer.max
[1] 2147483647
> as.integer(2147483647)
[1] 2147483647
> as.integer(2147483648)
[1] NA
Warning message:
NAs introduced by coercion
Double-precision numbers (i.e. the 'numeric' type) are able to represent
a larger range of integer values, from -(2^.Machine$double.digits) to
+(2^.Machine$double.digits). If you go outside that range, some integers
are not exactly representable.
> options(digits = 22)
> print(max.num <- 2 ^ .Machine$double.digits)
[1] 9007199254740992
> (max.num) - (max.num - 1)
[1] 1
> (max.num + 1) - (max.num)
[1] 0
> (max.num + 2) - (max.num + 1)
[1] 2
> If I need to setup by myself what is the maximum value?
I don't understand what you mean.
--
Mikko Korpela
More information about the R-help
mailing list