Skip to content
Back to formatted view

Raw Message

Message-ID: <6ph1vr7qj5b.fsf@gopher4.fhcrc.org>
Date: 2009-05-02T21:39:28Z
From: Martin Morgan
Subject: integer ranges in R vs C and Java
In-Reply-To: <1e7471d50905021420k5259fc80obe3f2158dd77b39e@mail.gmail.com> (Saptarshi Guha's message of "Sat, 2 May 2009 17:20:45 -0400")

You've hit on the reason -- representation of NA

src/main/arithmetic.c:157:    R_NaInt = INT_MIN;

(R-devel seems more appropriate for this question).

Martin


Saptarshi Guha <saptarshi.guha at gmail.com> writes:

> 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
>
> ______________________________________________
> R-help at 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.

-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793