Wonder if there are any nontrivial ways of finding number\'s sign (signum function)? May be shorter / faster / more elegant solutions than the obvious one
I don't see any practical sence of returning -0 and 0 from Math.sign so my version is:
Math.sign
function sign(x) { x = Number(x); if (isNaN(x)) { return NaN; } if (x === -Infinity || 1 / x < 0) { return -1; } return 1; }; sign(100); // 1 sign(-100); // -1 sign(0); // 1 sign(-0); // -1