| Title: | Binary Exponentiation |
|---|---|
| Description: | Fast exponentiation when the exponent is an integer. |
| Authors: | Jonathan Debove [aut, cre] |
| Maintainer: | Jonathan Debove <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.3 |
| Built: | 2026-06-02 07:20:40 UTC |
| Source: | https://github.com/cran/pow.int |
Fast exponentiation when the exponent is an integer.
pow.int(x, n) x %^% npow.int(x, n) x %^% n
x |
a numeric vector giving the base. |
n |
an integer vector giving the exponent. |
A numeric vector.
This function is just a wrapper around R_pow_di in the Rmath
library.
Jonathan Debove
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]))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]))