You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

next_pow2

Returns the next power-of-two greater than or equal to a given value.

n = next_pow2(1010);    //  n == 1024
n = next_pow2(1024);    //  n == 1024
n = next_pow2(1030);    //  n == 2048
next_pow2(n)
Returns the next power-of-two greater than or equal to a given value.
COPY/// @func   next_pow2(n)
///
/// @desc   Returns the next power-of-two greater than or equal to a given value.
///
/// @param  {real}      n       positive integer
///
/// @return {real}      power-of-two
///
/// GMLscripts.com/license

function next_pow2(n)
{
    return 1 << ceil(log2(n));
}

Contributors: davesch, xot

GitHub: View · Commits · Blame · Raw