This was written by Mr Speaker. Posted on at 5:03 pm. Filed under Javascript. Bookmark the permalink. Follow comments here with the RSS feed. Trackbacks are closed, but you can post a comment.
That’s just a lil’ trick: the ~ is JavaScript’s bitwise NOT operator. Applying it twice (NOT NOT) is just a cheeky way of doing a Math.floor for positive numbers. But it’s waaaay faster than “Math.floor” (and just slightly faster than “<<0″)
Though in this case, speed is not really an issue and I should have just done Math.floor for readability. Sorry 'bout that!
3 Comments
You clearly have too much time on your hands. Extremely cool.
In your code I noticed you used a funtion name “~~()”. Can you explain what this function does and if it is a part of the core Javascript language.
Thanks
That’s just a lil’ trick: the ~ is JavaScript’s bitwise NOT operator. Applying it twice (NOT NOT) is just a cheeky way of doing a Math.floor for positive numbers. But it’s waaaay faster than “Math.floor” (and just slightly faster than “<<0″)
Though in this case, speed is not really an issue and I should have just done Math.floor for readability. Sorry 'bout that!
Post a Comment