Movatterモバイル変換


[0]ホーム

URL:


Dirk Eddelbuettel
RcppInt64:Bindings for Passing integer64 To And From C++

CILicenseCRANDependenciesLast Commit

Motivation

While R has nonative support for 64-bit integer values, thebit64package by Jens Oehlschlägel is widely used to fill this gap by(very carefully) passing the bitmaps ofint64_t valuesaround indouble. This works on the R side by virtue of aS3 classinteger64 with proper dispatching, and on theC/C++ side where the values can be past bymemcpy. What onecannot do is simply copying or casting: the tradeoff made inrepresenting adouble with as large a range is that the‘delta’ between values is not constant acros the range and naive castingbetween both representationwill be lossy and distortvalues.

This package contains helper functions that were previously appearingin helper header files in different packages, and reorganizes them alongwith a proper unit tests. The key header file provided here can beincluded directly. Function to assertinteger64 source,convert to and from in both scalar and vector cases as well as a pair ofas<>() andwrap() converters areprovided.

Example

The example for the included demonstration function show how a vectorofinteger64 values (here spanning the power of 10 rangingfrom 0 to 18) can be received in C++, altered (where we just add one)and returned, all while maintaininginteger64 akaint64_t type.

>example(Int64toInt64)I64I64># generate all powers of 10 fro 0 .. 18I64I64> v<- bit64::as.integer64(10^seq(0,18))I64I64># pass them to function which will add one to each, print  and returnI64I64>Int64toInt64(v)2111011001100011000011000001100000011000000011000000001100000000011000000000011000000000001100000000000011000000000000011000000000000001100000000000000011000000000000000011000000000000000001integer64 [1]211101 [4]100110001100001 [7]100000110000001100000001[10]100000000110000000001100000000001[13]100000000000110000000000001100000000000001[16]100000000000000110000000000000001100000000000000001[19]1000000000000000001>

Contributing

Any problems, bug reports, or features requests for the package canbe submitted and handled most conveniently asGithubissues in the repository.

Before submitting pull requests, it is frequently preferable to firstdiscuss need and scope in such an issue ticket. See the fileContributing.md(in theRcpp repo) for abrief discussion.

Author

Dirk Eddelbuettel

License

GPL (>= 2)

Initially created: Tue Sep 5 08:19:00 PM CDT 2023
Last modified: Sun May 26 10:12:06 CDT 2024


[8]
ページ先頭

©2009-2025 Movatter.jp