diff --git a/source/Ox/js/Math.js b/source/Ox/js/Math.js index 8ae31831..9f387665 100644 --- a/source/Ox/js/Math.js +++ b/source/Ox/js/Math.js @@ -3,6 +3,8 @@ /*@ Ox.acosh Inverse hyperbolic cosine Missing from `Math`. + > Ox.acosh(1) + 0 @*/ Ox.acosh = function(x) { return Math.log(x + Math.sqrt(x * x - 1)); @@ -21,11 +23,23 @@ Ox.asinh = function(x) { /*@ Ox.atanh Inverse hyperbolic tangent Missing from `Math`. + > Ox.atanh(0) + 0 @*/ Ox.atanh = function(x) { return 0.5 * Math.log((1 + x) / (1 - x)); }; +/*@ +Ox.cosh Hyperbolic cosine + Missing from `Math` + > Ox.cosh(0) + 1 +@*/ +Ox.cosh = function(x) { + return (Math.exp(x) + Math.exp(-x)) / 2; +}; + /*@ Ox.deg Takes radians, returns degrees Missing from `Math`. @@ -152,14 +166,17 @@ Ox.sign Returns the sign of a number (-1, 0 or 1) > Ox.sign(-Infinity) -1 > Ox.sign(-0) - 0 + -0 + > Ox.sign(NaN) + NaN > Ox.sign(0) 0 > Ox.sign(Infinity) 1 @*/ Ox.sign = function(x) { - return x !== x || x === 0 ? +x : x < 0 ? -1 : 1; + x = +x; + return x !== x || x === 0 ? x : x < 0 ? -1 : 1; }; /*@ @@ -175,6 +192,8 @@ Ox.sinh = function(x) { /*@ Ox.tanh Hyperbolic tangent Missing from `Math`. + > Ox.tanh(0) + 0 @*/ Ox.tanh = function(x) { return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));