Merge pull request #4248 from marcjansen/math-es6-2015
Use Math.cosh of ES6/2015 if available
This commit is contained in:
+21
-3
@@ -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.
|
* @param {number} x X.
|
||||||
* @return {number} Hyperbolic cosine of x.
|
* @return {number} Hyperbolic cosine of x.
|
||||||
*/
|
*/
|
||||||
ol.math.cosh = function(x) {
|
ol.math.cosh = (function() {
|
||||||
return (Math.exp(x) + Math.exp(-x)) / 2;
|
// 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;
|
||||||
|
}());
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user