add sign and trunc

This commit is contained in:
rolux 2012-06-13 08:12:01 +02:00
parent c2ae5d3f4c
commit 8df96dd8fb

View file

@ -147,6 +147,21 @@ Ox.round = function(number, decimals) {
return Math.round(number * pow) / pow;
};
/*@
Ox.sign <f> Returns the sign of a number (-1, 0 or 1)
> Ox.sign(-Infinity)
-1
> Ox.sign(-0)
0
> Ox.sign(0)
0
> Ox.sign(Infinity)
1
@*/
Ox.sign = function(x) {
return x !== x || x === 0 ? x : x < 0 ? -1 : 1;
};
/*@
Ox.sinh <f> Hyperbolic sine
Missing from `Math`.
@ -164,3 +179,12 @@ Ox.tanh <f> Hyperbolic tangent
Ox.tanh = function(x) {
return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));
};
/*@
Ox.trunc <f> Truncates a number
> Ox.trunc(-1.5)
-1
@*/
Ox.trunc = function(x) {
return ~~x;
};