R/nextpow2.R

Defines functions nextpow2

Documented in nextpow2

###
### $Id: nextpow2.R 29 2022-05-30 23:02:22Z proebuck $
###
### Next higher power of 2.
###


##-----------------------------------------------------------------------------
nextpow2 <- function(x) {
    if (!(is.numeric(x) || is.complex(x))) {
        stop(sprintf("argument %s must be numeric or complex",
                     sQuote('x')))
    }

    if (length(x) == 0) {
        return(numeric(0))
    }

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

Try the matlab package in your browser

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

matlab documentation built on July 1, 2024, 5:07 p.m.