Created
January 23, 2014 10:31
-
-
Save Zegnat/8576336 to your computer and use it in GitHub Desktop.
Some extensions to Sugar.
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
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