as.double2 {RcppFastFloat} | R Documentation |
Ultra efficient string-to-double
Conversion
Description
For character
vector
s, as.double2()
is a
drop-in replacement for base::as.double()
.
Usage
as.double2(x)
Arguments
x |
A vector of type |
See Also
as.double()
Examples
set.seed(8675309)
input <- sample(c(
paste0(" \r\n\t\f\v", c(0.0, sqrt(seq(1, 10))), " \r\n\t\f\v"),
c("NaN", "-NaN", "nan", "-nan",
"Inf", "-Inf", "inf", "-inf", "infinity", "-infinity",
NA_character_,
" 1970-01-01", "1970-01-02 ")
))
input
suppressWarnings(as.double2(input)) # NAs introduced by coercion
comparison <- suppressWarnings(
matrix(c(as.double(input), as.double2(input)),
ncol = 2L,
dimnames = list(NULL, c("as.double()", "as.double2()")))
)
comparison
all.equal(comparison[, "as.double()"], comparison[, "as.double2()"])
[Package RcppFastFloat version 0.0.4 Index]