Use Math.cosh of ES6/2015 if available
This commit is contained in:
@@ -17,13 +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) {
|
||||
var y = Math.exp(x);
|
||||
return (y + 1 / y) / 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;
|
||||
}());
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user