| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 1× 1× 44× 1× 1× | var mathUtil = {};
mathUtil.isPowerOfTwo = function (value) {
return (value & (value - 1)) === 0;
};
mathUtil.nextPowerOfTwo = function (value) {
value --;
value |= value >> 1;
value |= value >> 2;
value |= value >> 4;
value |= value >> 8;
value |= value >> 16;
value ++;
return value;
};
mathUtil.nearestPowerOfTwo = function (value) {
return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
};
export default mathUtil;
|