Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nextpow2

Next Power of 2


Description

Smallest power of 2 greater than the argument.

Usage

nextpow2(x)

Arguments

x

numeric scalar, vector, or matrix

Details

Computes the smalest integer n such that abs(x) ≤ 2^n. IF x is a vector or matrix, returns the result component-wise. For negative or complex values, the absolute value will be taken.

Value

an integer n such that x ≤ 2^n.

See Also

Examples

nextpow2(10)                   #=> 4
  nextpow2(1:10)                 #=> 0 1 2 2 3 3 3 3 4 4
  nextpow2(-2^10)                #=> 10
  nextpow2(.Machine$double.eps)  #=> -52

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.