C99 'math' Library Functions (where Not in Standard aka 'Base' R)
Provides simple R versions of those C99 “math lib” / “libmath” / “libm” functions that are not (yet) in standard (aka ‘base’ R).
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)x, y |
numeric vector(s); will be recycled to common length. |
Martin Maechler
Wikipedia (2020) C mathematical functions https://en.wikipedia.org/wiki/C_mathematical_functions
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)Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.