UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

42 lines (34 loc) 715 B
/** * Count trailing zeroes * adapted from https://github.com/git/git/blob/bcd6bc478adc4951d57ec597c44b12ee74bc88fb/ewah/ewok.h#L44 * @param {number} x expected to be an integer * @return {number} */ export function ctz32(x) { let _x = x; let n = 0; if ((_x & 0xffff) === 0) { _x >>= 16; n += 16; } if ((_x & 0xff) === 0) { _x >>= 8; n += 8; } if ((_x & 0xf) === 0) { _x >>= 4; n += 4; } if ((_x & 0x3) === 0) { _x >>= 2; n += 2; } if ((_x & 0x1) === 0) { _x >>= 1; n += 1; } if (_x === 0) { n += 1; } return n; }