From simon.urbanek at r-project.org  Fri Jun 19 00:44:30 2009
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 18 Jun 2009 18:44:30 -0400
Subject: [Rd] ScalarLong?
In-Reply-To: <c2350ba40906181334j14fbb298j52194bfebf267212@mail.gmail.com>
References: <c2350ba40906181334j14fbb298j52194bfebf267212@mail.gmail.com>
Message-ID: <2C957AF9-E377-49C6-97D2-0E2CBF2DBB10@r-project.org>


On Jun 18, 2009, at 16:34 , Kynn Jones wrote:

> I was surprised to see that there is a ScalarInteger function in
> Rinlinedfuns.h, but nothing like ScalarLong.
>
> How can one create an R-integer from a C long?
>

There is no such thing as "long" in R (*), so one cannot make a  
"scalar long" vector in R. But to answer your question (how to create  
"R-integer" - interpreted as "integer vector of length one") it's simply
ScalarInteger((int) myLong)

(*) - on 32-bit systems long and int are equivalent, so the conversion  
is lossless, on 64-bit systems there is no way to store a "long" in R  
integer without loss of precision. The only lossless way on 64-bit  
systems is to store it in a raw vector of 8 bytes (but then there's  
not much you can do with it ...). For practical purposes it is usually  
sufficient to convert it to double (real vector in R) since you have  
at least guaranteed 52-bit precision (technically even more) and can  
perform the usual operations on it.

Cheers,
Simon



[Rd] ScalarLong?
Simon Urbanek