pow.int {pow.int}R Documentation

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]))

[Package pow.int version 1.3 Index]