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

mathC99

C99 'math' Library Functions (where Not in Standard aka 'Base' R)


Description

Provides simple R versions of those C99 “math lib” / “libmath” / “libm” functions that are not (yet) in standard (aka ‘base’ R).

Usage

logB(x) # C's logb(x), numeric integer-valued "log2".
         # R's logb() is defined as "log wrt base"
ilogb(x) # == logB(), but of *type* integer

fpclassify(x)
isnormal(x)
nearbyint(x)
signbit(x)

nextafter(x, y)
nexttoward(x, y)

Arguments

x, y

numeric vector(s); will be recycled to common length.

Value

a numeric (double or integer) vector of the same (or recycled) length of x (and y where appropriate) with the values of <fn>(x) for the corresponding C99 libmath function <fn>.

Author(s)

Martin Maechler

References

Wikipedia (2020) C mathematical functions https://en.wikipedia.org/wiki/C_mathematical_functions

See Also

Examples

x <- (1:20)*pi
stopifnot(ilogb (x) == logB (x),  is.integer(ilogb(x)),
          ilogb(-x) == logB(-x),  is.double ( logB(x)))
cbind(x, "2^il(x)"= 2^logB(x), ilogb = ilogb(x), signbit = signbit(x),
         fpclassify = fpclassify(x), isnormal = isnormal(x))

x <- c(2^-(10:22), rexp(1000));
summary(x / 2^ilogb(x)) # in   [1, 2)  interval
stopifnot(nearbyint(x) == round(x))

nextafter(-0, +0)
nextafter(+0,  1)
nextafter(+0, -1)
nextafter(Inf, -1)
nextafter(-Inf, 0)

round

Rounding to Decimal Digits

v0.20-0
AGPL (>= 3) | file LICENSE
Authors
Martin Maechler [aut, cre] (<https://orcid.org/0000-0002-8685-9910>), R-core [ctb] ("r1.C" only)
Initial release
2021-01-04

We don't support your browser anymore

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