eddelbuettel / rcppsimdjson

Rcpp Bindings for the 'simdjson' Header Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to "Force" 64-bit Integers

knapply opened this issue · comments

I came across a use case involving merging multiple parsed objects that should all be bit64::integer64s, but some of the objects don't contain any values exceeding the INT_MAX threshold (meaning they were downcasted to R's regular 32-bit integers).

vec_int <- 1:3
vec_int64 <- bit64::as.integer64(c("3000000000", "3000000001", "3000000002"))

# `c()`'s behavior
c(vec_int, vec_int64)
#> [1]  1.000000e+00  2.000000e+00  3.000000e+00 1.482197e-314 1.482197e-314
#> [6] 1.482197e-314

# the result we want
c(bit64::as.integer64(vec_int), vec_int64)
#> integer64
#> [1] 1          2          3          3000000000 3000000001 3000000002

Adding an "always" option to int64_policy= that forces all integers to be returned as bit64::integer64s will eliminate this post-parse processing hassle.

In favor--that is a tricky topic. Declaring up-front may indeed be cleanest.

Closed by merging #55