mirror of
https://github.com/photonstorm/phaser
synced 2025-01-11 12:48:50 +00:00
25 lines
597 B
JavaScript
25 lines
597 B
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
*/
|
|
|
|
/**
|
|
* Returns the nearest power of 2 to the given `value`.
|
|
*
|
|
* @function Phaser.Math.Pow2.GetPowerOfTwo
|
|
* @since 3.0.0
|
|
*
|
|
* @param {number} value - [description]
|
|
*
|
|
* @return {integer} [description]
|
|
*/
|
|
var GetPowerOfTwo = function (value)
|
|
{
|
|
// Math.log(2)
|
|
var index = Math.log(value) / 0.6931471805599453;
|
|
|
|
return (1 << Math.ceil(index));
|
|
};
|
|
|
|
module.exports = GetPowerOfTwo;
|