Last active
August 29, 2015 14:17
-
-
Save joa/23e8b6e11c1f06c041b8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// http://jsperf.com/double2int | |
function double2int=function(x){ | |
if(isNaN(x)) | |
return 0; | |
if(x==Infinity||x>0x7fffffff) | |
return 0x7fffffff; | |
if(x==-Infinity||x<-0x80000000) | |
return -0x80000000; | |
return x|0; | |
}; | |
function double2int=function(x){ | |
if(x!==x) | |
return 0; | |
if(x>0x7fffffff) | |
return 0x7fffffff; | |
if(x<-0x80000000) | |
return -0x80000000; | |
return x|0; | |
}; | |
function double2int=function(x) { | |
return Math.min(Math.max(x, -0x80000000), 0x7fffffff)|0 | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment