Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sapplyMpfr

Apply a Function over a "mpfr" Vector


Description

Users may be disappointed to note that sapply() or vapply() typically do not work with "mpfr" numbers.

This is a simple (but strong) approach to work around the problem, based on lapply().

Note that this is not yet as flexible as sapply() for atomic vectors.

Usage

sapplyMpfr(X, FUN, ...)

Arguments

X

a vector, possibly of class "mpfr".

FUN

a function returning an "mpfr" number. (TODO: A function returning a vector of mpfr numbers or even "mpfrArray").

...

further arguments passed to lapply, typically further arguments to FUN.

Value

an "mpfr" vector, typically of the same length as X.

Note

Another workaround could be to use

res <- lapply(....)
    sapply(res, asNumeric)

Author(s)

Martin Maechler

Examples

## The function is simply defined as
function (X, FUN, ...)
  new("mpfr", unlist(lapply(X, FUN, ...), recursive = FALSE))

if(require("Bessel")) # here X, is simple
  bImp <- sapplyMpfr(0:4, function(k)
                     besselI.nuAsym(mpfr(1.31e9, 128), 10, expon.scaled=TRUE, k.max=k))

Rmpfr

R MPFR - Multiple Precision Floating-Point Reliable

v0.8-4
GPL (>= 2)
Authors
Martin Maechler [aut, cre] (<https://orcid.org/0000-0002-8685-9910>), Richard M. Heiberger [ctb] (formatHex(), *Bin, *Dec), John C. Nash [ctb] (hjkMpfr(), origin of unirootR()), Hans W. Borchers [ctb] (optimizeR(*, "GoldenRatio"); origin of hjkMpfr())
Initial release
2021-04-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.