Skip to content

Instantly share code, notes, and snippets.

@timohausmann
Last active December 14, 2015 00:19
Show Gist options
  • Save timohausmann/4997846 to your computer and use it in GitHub Desktop.
Save timohausmann/4997846 to your computer and use it in GitHub Desktop.
Javascript Math: get the signature of a number
/**
* 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