I will need 64 bits integer in my package in a close future. I'm studying the feasibility based on the bit64
package. Basically I plan to have one or more columns in a data.table
with an interger64
S3 class and I plan to pass this table to C++ functions using Rcpp.
The following nanotime example from Rcpp gallery explains clearly how a vector of 64 bits int is built upon a vector of double and explain how to create an integer64
object from C++ to R.
I'm now wondering how to deal with an interger64
from R to C++. I guess I can invert the principle.
void useInt64(NumericVector v)
{
double len = v.size();
std::vector<int64_t> n(len);
// transfers values 'keeping bits' but changing type
// using reinterpret_cast would get us a warning
std::memcpy(&(n[0]), &(v[0]), len * sizeof(double));
// use n in further computations
}
Is that correct? Is there another way to do that? Can we use a wrapper as<std::vector<int64_t>>(v)
? For this last question I guess the conversion is not based on a bit to bit copy.