pow: X to Power of Y - R C API 'R_pow()'

View source: R/utils.R

powR Documentation

X to Power of Y – R C API R_pow()

Description

pow(x,y) calls R C API ‘Rmathlib’'s R_pow(x,y) function to compute x^y or when try.int.y is true (as by default), and y is integer valued and fits into integer range, R_pow_di(x,y).

pow_di(x,y) with integer y calls R mathlib's R_pow_di(x,y).

Usage

pow   (x, y, try.int.y = TRUE)
pow_di(x, y)
.pow  (x, y)

Arguments

x

a numeric vector.

y

a numeric or in the case of pow_di() integer vector.

try.int.y

logical indicating if pow() should check if y is integer valued and fits into integer range, and in that case call pow_di() automatically.

Details

In January 2024, I found (e.g., in ‘tests/pow-tst.R’) that the accuracy of pow_di(), i.e., also the C function R_pow_di() in R's API is of much lower precision than R's x^y or (equivalently) R_pow(x,y) in R's API, notably on Linux and macOS, using glib etc, sometimes as soon as y \ge 6 or so.

.pow(x,y) is identical to pow(x,y, try.int.y = FALSE)

Value

a numeric vector like x or y which are recycled to common length, of course.

Author(s)

Martin Maechler

See Also

Base R's ^ “operator”.

Examples


set.seed(27)
x <- rnorm(100)
y <- 0:9
stopifnot(exprs = {
    all.equal(x^y, pow(x,y))
    all.equal(x^y, pow(x,y, FALSE))
    all.equal(x^y, pow_di(x,y))
})

DPQ documentation built on Sept. 11, 2024, 8:37 p.m.