[R] Max value of an integer

2012-01-11 Thread Rui Esteves
Hi.
Is there any constant that represents the maximum value of an integer?
If I need to setup by myself what is the maximum value?
Best,
Rui

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Max value of an integer

2012-01-11 Thread Berend Hasselman

rmx wrote
 
 Hi.
 Is there any constant that represents the maximum value of an integer?
 If I need to setup by myself what is the maximum value?
 

?.Machine

i.e.

.Machine$integer.max

Berend


--
View this message in context: 
http://r.789695.n4.nabble.com/Max-value-of-an-integer-tp4284953p4285054.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Max value of an integer

2012-01-11 Thread Mikko Korpela
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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.