https://github.com/cran/pracma
Raw File
Tip revision: 26e049d70b4a1c237987e260cba68f6a9413736c authored by Hans W. Borchers on 09 April 2019, 04:10:07 UTC
version 2.2.5
Tip revision: 26e049d
pow2.R
###
### POW2.R  Raise 2 to some power
###

pow2 <- function(f, e) {
    if (!is.numeric(f) && !is.complex(f))
        stop("Argument 'f' must be numeric or complex.")
    if (missing(e)) {
        e <- f
        f <- rep(1, length(e))
    } else {
        if (!is.numeric(e) && !is.complex(e))
            stop("Argument 'e' must be numeric or complex.")
        if (is.complex(f) || is.complex(e)) {
            f <- Re(f)
            e <- Re(e)
            warning("Imaginary part of arguments ignored.")
        }
    }
    if (length(f) != length(e))
        stop("Arguments 'e' and 'f' must be of same length.")

    return(f * 2^e)
}
back to top