4 ms·
Just like pcwalton said, you can trick js engines to do real 32-bit arithmetic. (x|0 + y|0)|0 tells the engine that it's 32-bits all the way through, and it opt
by jlongster 14y ago
Just like pcwalton said, you can trick js engines to do real 32-bit arithmetic. (x|0 + y|0)|0 tells the engine that it's 32-bits all the way through, and it optimizes it appropriately and never touches floats.
64-bits is a problem, yes, but again like pcwalton said, it is being worked on for post ES6 era. Obviously, if the Unreal Engine is working, it's not necessarily critical & a show-stopper, but it is needed for certain things.
Edit: Math.imul is needed because the number can become large enough to where the engine converts it to a double, and then converts it back and you lose precision (I think that's how it works). It's the only arithmetic that needs fixing.
- niggler 14y ago"(x|0 + y|0)|0 tells the engine that it's 32-bits all the way through" You conveniently skipped the complaint: "Even the modest 32-bit integer multiplication is tricky (you only have 52-53 bits of mantissa)"
- jlongster 14y ago@niggler I did at first but I added a quick edit after I posted. It's not a hard thing to fix.
- niggler 14y ago"It's not a hard thing to fix." But then you get back into the game of asking browser vendors to make changes, which was one of the original selling points of asm.js (that browser vendors didn't have to make changes).
- jlongster 14y agoSure, it's unfortunate, but it's one obscure edge case that they can implement instantly. They are still pushed to implement asm.js anyway, so that just comes with it. If they don't, things like BananaBread do still run, so it's not required, it's just an obscure edge case.
- BrendanEich 14y agoJS is changing, ES6 is coming. Browser vendors want changes and are on board. They're also under competitive pressure. But in what scenario is the much greater work to add Pepper and PNaCl support going to prevail? You have to assume JS dies or freezes, and there's exogenous pressure for something new. Instead, we see demand for JS to evolve (Mozilla serves this, we aren't just ginning it up, believe me!). So browser vendors would have to do two big jobs: tend the web standards and evolve them, and put in a new native code runtime alongside. That is simply not going to happen outside of Google, which can afford endless impossible-to-standardize boondoggles. It is both uneconomic, and technically inferior to a more minimal evolutionary path-finding solution. /be
- fffaaa 14y agook