@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
23 lines (19 loc) • 498 B
JavaScript
/**
* Returns next nearest power of two based on the input. If input is already power of two - result will be the same as input.
* @example 2 -> 2
* @example 7 -> 8
* @example 10 -> 16
* @see http://developer.classpath.org/doc/java/lang/Integer-source.html
* @param {number} v
* @return {number}
*/
export function ceilPowerOfTwo(v) {
let x = v - 1;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;
return x;
}