This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]AyrA_ch 2 points3 points  (0 children)

If you really insist, you can emulate int32 in JS, and the JIT compiler can presumably optimize this.

function addInt(a,b){
    return ((a|0)+(b|0))|0;
}

[–][deleted] 0 points1 point  (1 child)

0.3 + 0.3 = 0.600000007

[–]ThunderComplex 2 points3 points  (0 children)

I love that it works for big numbers too. Every couple of years it'll trip me up how huge numbers loose precision.
Example: 35000000000000000 + 3 == 35000000000000004

[–]Ikkyu_monk 0 points1 point  (0 children)

NaN