# all files / src/math/ util.js

35.71% Statements 5/14
100% Branches 0/0
33.33% Functions 1/3
35.71% Lines 5/14

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    241×

    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;