3 ms·
A good thing to keep in mind is the behavior at the extremities. If you look at negative numbers (Math.floor(-1.1) == -2, whereas parseInt("-1.1", 10) == -1, a
by shuzchen 14y ago
A good thing to keep in mind is the behavior at the extremities. If you look at negative numbers (Math.floor(-1.1) == -2, whereas parseInt("-1.1", 10) == -1, and -1.1 << 0 == -1) and numbers greater than 2^32 (Math.floor and parseInt work for those values, but bitwise shifting always returns 0) the behavior is different.
- ricardobeat 14y agoMath.floor is the right choice 99% of the time for three reasons: 1. it will always behave correctly (barring implementation bugs) 2. readable/mantainable code comes first 3. leave tricks to the interpreter 4. you're not gonna do 60 million flooring ops/s 5. -1.1 is really -2+.9 The author missed the ~~1.1 trick (essentially the same as << 0).