2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-10-06 03:52:41 +00:00
|
|
|
/**
|
|
|
|
* Returns the nearest power of 2 to the given `value`.
|
|
|
|
*
|
|
|
|
* @function Phaser.Math.Pow2.GetPowerOfTwo
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-24 11:06:44 +00:00
|
|
|
* @param {number} value - The value.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2018-05-24 11:06:44 +00:00
|
|
|
* @return {integer} The nearest power of 2 to `value`.
|
2017-10-06 03:52:41 +00:00
|
|
|
*/
|
2016-12-13 16:12:25 +00:00
|
|
|
var GetPowerOfTwo = function (value)
|
2016-12-07 17:16:59 +00:00
|
|
|
{
|
|
|
|
var index = Math.log(value) / 0.6931471805599453;
|
|
|
|
|
|
|
|
return (1 << Math.ceil(index));
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = GetPowerOfTwo;
|