video: https://www.youtube.com/watch?v=bjqNK1jA77M
slides: http://www.inf.puc-rio.br/~roberto/talks/ws2014.pdf
The main advantages of adding integers to Lua are:
* For some things you need 2^64 bits, not just 2^53 (file handles, crypto algorithms with bitwise operations, etc)
* Some embedded systems don't have hardware support for floating point (you could compile Lua with integers instead of double but it was very hacky)
* It simplifies the C API. There are some things in the API and various internals in the implementation that benefit from separating integers and floating point numbers.
Sometimes the hardware/OS/drivers/something else is buggy with floats...
I once designed a game that needed integers for some things, and implemented it with Lua, on Windows machines it started to sometimes give VERY WRONG results (even in very short operations, like reporting that 5+5 == 11 or that 8+2 == 9, those are actual errors, not just short numbers to make typing easier).
Later I found out it had to do with a infamous directX bug, where it changed the settings of the floating point units without permission, and sometimes this resulted into really, really, really funky floating point math, meaning that all math made with Lua in those cases maybe could be completely wrong.
Back then when I found this (The issue, not the reason for it), many Lua devs kept telling me I as crazy or a troll, thankfully one guy in freenode.net #lua had the brilliance to tell me to check if it was the DX issue (and it was... the issue don't happened on Linux or OSX)
There are two main reasons: - Modern systems are now 64-bit and they sometimes have APIs that demand 64-bit integers. (For example, file APIs that deal in bytes like fread).
- Small, embedded systems that are 32-bit or less, which don't have good floating point hardware and are RAM constrained. Lua 5.3 now means double no longer has to be used to represent 32-bit integers. Instead integers can be directly (avoiding floating point for performance) and floating point sizes can be reduced down to float instead of double (reducing the size of internal objects).
Roberto Ierusalimschy (Lua creator) has given several talks about why bring integers to Lua 5.3. https://www.youtube.com/watch?v=bjqNK1jA77M
Until you divide them by three.
There is a time and a place for integer arithmetic. You could get there with liberal use of truncation, but it reads better as native integer arithmetic.
The slope is slippery, time to resist or embrace native complex, rationals, and quaternions… I only stop the list here because it is as much as I've ever used in real world code.
Do write some good test cases though that compare to someone else's implementation. I accidentally wrote my multiplication backwards and didn't catch it for a long time. I just had a vague feeling that something was wrong every time I wrote rotation code.
Linden Scripting Language even provides quarternions conversion with llEuler2Rot, llRot2Euler and llAxisAngle2Rot. See: http://wiki.secondlife.com/wiki/Quaternion for an introduction.
So quaternions are useful for 3d games, and games are a hot topic for Lua. But its not required, that complex numbers or quarternions are part of base language. See: http://lua-users.org/wiki/ComplexNumbers - thats easy to implement with Lua prototyping.
A somewhat related thing(not addressed by this yet) is about Electric Imp, who had to switch to a different language from lua(which they started with). The reason was that they needed to store values for an LED array, and the only data type is tables, and all integers are 32 bit.
Not sure but they might have used user defined types, with the arrays stuff being done in C, might have been easier.