Skip to content
Prev 6431 / 10988 Next

[Rcpp-devel] long long

I've put it in with some text explaining it.

// long long and unssigned long long support.
//
// given the current restriction of what might go to CRAN
// we can only use long long if we are running a gcc compatible (e.g. clang)
// compiler and the type is actually available (hence the test for 
__LONG_LONG_MAX__)
// even then, we cannot use long long as is, we first have to "hide" it
// behind the __extension__ so that -pedantic stops giving warnings about
// compliance with C++98
//
// client code may use the facilities we provide for long long (wrap, 
etc ...)
// but not using long long directly, because then it is not CRAN proof.
// So client code must use the rcpp_long_long_type and rcpp_ulong_long_type
// types
//
// e.g. code like this is not good:
//
// long long x = 2 ;
//
// but code like this is CRAN proof
//
// rcpp_long_long_type x = 2 ;
//
// Note that if you don't distribute your code to CRAN and you don't use 
the
// -pedantic option, then you can use long long
#if defined(__GNUC__) &&  defined(__LONG_LONG_MAX__)
     __extension__ typedef long long int rcpp_long_long_type;
     __extension__ typedef unsigned long long int rcpp_ulong_long_type;
     #define RCPP_HAS_LONG_LONG_TYPES
#endif

I'll start a discussion on R-devel if needed.



For now this gives us wrap<rcpp_long_long_type> and wrap< 
vector<rcpp_long_long_type> >, etc ... that for now generate numeric 
vector (so for a precision going up to 52 or 53(I can never remember 
this one) bits of precision, so better than what it used to be (32).

It might be worth investigating generating something compatible with the 
bit64 or the int64 package.

int64 stores a long long vector as a list of integer vectors of length 2.

bit64 is smarter and uses the bits of a double. And it is faster, as its 
documentation cares to show in great detail.

Other packages (e.g. data.table) have adopted the way bit64 does it. And 
it does not require that we depend on bit64. That's what 
data.table::fread does when reading integer64 columns: it stores them as 
a numeric vector with the appropriate class suitabe for bit64. Then if 
bit64 is loaded then the object is treated as a 64 bit integer vector. 
If it is not loaded, the values are just weird looking numeric vector.

Even though I wrote int64, I might actually lean towards generating 
something to play along with bit64 rather than int64.

However bit64 does not seem to implement unsigned 64 bit vectors (i.e. 
rcpp_ulong_long_type, aka unsigned long long).

Romain

Le 19/09/13 15:48, Romain Francois a ?crit :