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.
/// next_pow2(n)
//
//  Returns the next power-of-two greater than or equal to a given value.
//
//      n       positive integer
//
/// GMLscripts.com/license
{
    var n = argument0 - 1;
    n |= (n >>  1);
    n |= (n >>  2);
    n |= (n >>  4);
    n |= (n >>  8);
    n |= (n >> 16);
    n |= (n >> 32);
    return n + 1;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw