Skip to content

Instantly share code, notes, and snippets.

@Zegnat
Created January 23, 2014 10:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Zegnat/8576336 to your computer and use it in GitHub Desktop.
Save Zegnat/8576336 to your computer and use it in GitHub Desktop.
Some extensions to Sugar.
Number.extend({
'sign': function() {
// http://stackoverflow.com/a/21294663/3225372
return typeof this === 'number' ? this ? this < 0 ? -1 : 1 : this === this ? this : NaN : NaN;
},
'isPositive': function() {
return this.sign() === 1;
},
'isNegative': function() {
return this.sign() === -1;
},
'isNegativeZero': function() {
// http://www.wirfs-brock.com/allen/posts/128
return this ? false : 1/this === -Infinity;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment