Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integers #13

Closed
knapply opened this issue May 23, 2020 · 1 comment
Closed

integers #13

knapply opened this issue May 23, 2020 · 1 comment

Comments

@knapply
Copy link
Collaborator

@knapply knapply commented May 23, 2020

simdjson itself uses int64_t and uint64_t for integers.

"Big-ints" are something I have to deal with on a regular basis, so it would be nice for RcppSimdJson to give the user options for handling them.

It's easy to check if numbers exceed R's integer type and safely cast accordingly, but I'd like the option to cast them to characters or bit64::integer64. At the R level, it looks something like this:

@eddelbuettel Is it acceptable to add bit64 to the DESCRIPTION's Suggests? I'm not suggesting RcppSimdJson code itself touch bit64 (except for testing), but this flexibility would be nice to have:

int64_opts <- list(double = 0, string = 1, integer64 = 2)

two_billion <- "2000000000"
three_billion <- "3000000000"

typeof(RcppSimdJson:::.parse_json(two_billion))
#> [1] "integer"
typeof(RcppSimdJson:::.parse_json(three_billion))
#> [1] "double"

RcppSimdJson:::.parse_json(three_billion, int64_T = int64_opts$double)
#> [1] 3e+09
RcppSimdJson:::.parse_json(three_billion, int64_T = int64_opts$string)
#> [1] "3000000000"

suppressPackageStartupMessages(library(bit64))
RcppSimdJson:::.parse_json(three_billion, int64_T = int64_opts$integer64)
#> integer64
#> [1] 3000000000

Underneath the hood it's just an enum-class template argument.

The current implementation can be found in @cran-dev/inst/include/RcppSimdJson/utils.hpp and an example R interface can be found in @cran-dev/src/rcppsimdjson_utils_check.cpp.

@eddelbuettel
Copy link
Owner

@eddelbuettel eddelbuettel commented May 23, 2020

Without having looked into details, and as much as I hate added Depends: yes!

I do the same in package nanotime which relies on bit64 and its integer64 class. We use that at work too. R's limited set of types bites us with large ints, and this is the best we have. And I have a good working relationship with Jens (upstream) so thumbs up from me.

This was referenced May 23, 2020
@knapply knapply closed this May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.