Add ol.math.roundUpToPowerOfTwo

This commit is contained in:
Tom Payne
2013-03-19 21:11:44 +01:00
parent 6c32170a08
commit 57abbddf50
2 changed files with 50 additions and 0 deletions

View File

@@ -29,6 +29,16 @@ ol.math.csch = function(x) {
};
/**
* @param {number} x X.
* @return {number} The smallest power of two greater than or equal to x.
*/
ol.math.roundUpToPowerOfTwo = function(x) {
goog.asserts.assert(0 < x);
return Math.pow(2, Math.ceil(Math.log(x) / Math.log(2)));
};
/**
* @param {number} x X.
* @return {number} Hyperbolic secant of x.