R/RcppExports.R

Defines functions parseExample as.double2

Documented in as.double2 parseExample

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Ultra efficient string-to-\code{double} Conversion
#'
#' For \code{character} \code{vector}s, \code{as.double2()} is a
#' drop-in replacement for \code{base::as.double()}.
#'
#' @param x A vector of type \code{character}.
#'
#' @seealso \code{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()"])
#'
as.double2 <- function(x) {
    .Call(`_RcppFastFloat_as_dbl`, x)
}

#' Floating Point Parsing Example
#'
#' This example is adapted from the example of the upstream README.md file, and generalized
#' to be called from R with variable input.
#'
#' @param input A character variable with text to parse including a simple default
#' @param verbose A boolean variable to show or suppress progress, defaults to true
#' @return A floating point scalar is returned on success; in case of parsing failure
#' the function exists via \code{stop()}.
#' @examples
#' parseExample()
parseExample <- function(input = "3.1416 xyz ", verbose = TRUE) {
    .Call(`_RcppFastFloat_parseExample`, input, verbose)
}

Try the RcppFastFloat package in your browser

Any scripts or data that you put into this service are public.

RcppFastFloat documentation built on April 3, 2025, 9:39 p.m.