Version: | 1.3 |
Date: | 2022-08-31 |
Title: | Binary Exponentiation |
Depends: | R (≥ 3.0.0) |
Description: | Fast exponentiation when the exponent is an integer. |
License: | GPL (≥ 3) |
NeedsCompilation: | yes |
Packaged: | 2022-08-31 16:34:14 UTC; jon |
Author: | Jonathan Debove [aut, cre] |
Maintainer: | Jonathan Debove <jondebove@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2022-08-31 18:50:02 UTC |
Binary Exponentiation
Description
Fast exponentiation when the exponent is an integer.
Usage
pow.int(x, n)
x %^% n
Arguments
x |
a numeric vector giving the base. |
n |
an integer vector giving the exponent. |
Value
A numeric vector.
Note
This function is just a wrapper around R_pow_di
in the Rmath
library.
Author(s)
Jonathan Debove
Examples
3 %^% 12L
# Basic tests
x <- runif(10)
n <- as.integer(runif(length(x), 0, 100))
stopifnot(all.equal(pow.int(x, n), x ^ n))
stopifnot(all.equal(pow.int(x[1], n), x[1] ^ n))
stopifnot(all.equal(pow.int(x, n[1]), x ^ n[1]))
stopifnot(all.equal(pow.int(x[1:2], n), x[1:2] ^ n))
stopifnot(all.equal(pow.int(x, n[1:2]), x ^ n[1:2]))