Merge pull request #4248 from marcjansen/math-es6-2015

Use Math.cosh of ES6/2015 if available
This commit is contained in:
Marc Jansen
2015-10-18 21:26:56 +02:00

View File

@@ -17,12 +17,30 @@ ol.math.clamp = function(value, min, max) {
/**
* Return the hyperbolic cosine of a given number. The method will use the
* native `Math.cosh` function if it is available, otherwise the hyperbolic
* cosine will be calculated via the reference implementation of the Mozilla
* developer network.
*
* @param {number} x X.
* @return {number} Hyperbolic cosine of x.
*/
ol.math.cosh = function(x) {
return (Math.exp(x) + Math.exp(-x)) / 2;
};
ol.math.cosh = (function() {
// Wrapped in a iife, to save the overhead of checking for the native
// implementation on every invocation.
var cosh;
if ('cosh' in Math) {
// The environment supports the native Math.cosh function, use it…
cosh = Math.cosh;
} else {
// … else, use the reference implementation of MDN:
cosh = function(x) {
var y = Math.exp(x);
return (y + 1 / y) / 2;
};
}
return cosh;
}());
/**