3 ms·
There is one langauge that once I complained to the authors that it was broken: Lua. Lua uses floating point by default, it can't make integer math at all, I m
by speeder 11y ago
There is one langauge that once I complained to the authors that it was broken: Lua.
Lua uses floating point by default, it can't make integer math at all, I made a game using Lua, back then DirectX had a bug where it would switch the floating point mode of the processor without permission, and sometimes the result was some extreme FPU imprecision.
Since Lua uses only the FPU for maths, even for integers, the result was that my game had lots of extremely bizarre results sometimes on Windows (while on Linux and OSX it worked as expected), it happened only once, but I saw 5+6 result in 13...
It was a really hard thing to debug, specially because of the flaming (when I asked about this on Lua IRC and forums, people flamed me endlessy, happily one guy in particular suggested me to check if it was the DX issue, and indeed it was).
- TY 11y agoVery interesting, I've never run into this, but I never used DX. For the simple example of 0.1+0.2, Lua does return 0.3 on Windows and OSX.
- mortehu 11y ago> Lua uses floating point by default, it can't make integer math at all JavaScript does this too. The fact is that with 64 bit floating point numbers, you can exactly represent every integer from -9007199254740992 to 9007199254740992, which is larger than the range of `int` on most systems anyway. 5+6 resulting in 13 is not an artifact of using floating point numbers. CPUs or GPUs don't randomly lose precision like that. 32 bit floating point numbers can exactly represent every integer from -16777216 to 16777216. See also http://www.lua.org/pil/2.3.html http://www.lua.org/pil/2.3.html
- speeder 11y agoBy the way, your reply was one of the most common replies to me that quickly turned into flaming (people offending me in all way they could to tell me Lua was perfect, and I was seeing things, because 32-bit is enough for the integers I was using...)
- recursive 11y ago> it happened only once, but I saw 5+6 result in 13 That's not the result of standard floating point arithmetic. I don't know what it is, but it's not that.