Last active
December 14, 2015 00:19
-
-
Save timohausmann/4997846 to your computer and use it in GitHub Desktop.
Javascript Math: get the signature of a number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* return the signature of a number. | |
* | |
* @param {number} val the input value | |
* @return {number} 1 if positive, -1 if negative, else 0 | |
*/ | |
Math.sign = function( val ) { | |
return val > 0 ? 1 : val < 0 ? -1 : 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment