R/nextpow2.R

Defines functions nextpow2

Documented in nextpow2

###
### NEXTPOW2.R  Next higher power of 2
###

nextpow2 <- function(x) {
    if (is.null(x) || length(x) == 0) return(c())
    if (!is.numeric(x) && !is.complex(x))
        stop("Argument 'x' must be a numeric/complex vector/matrix.")

    x[x == 0] <- 1
    return(ceiling(log2(abs(x))))
}

Try the pracma package in your browser

Any scripts or data that you put into this service are public.

pracma documentation built on March 19, 2024, 3:05 a.m.