pow {DPQ} | R 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 |
try.int.y |
logical indicating if |
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))
})