4 ms·
Same is true in Lua (only one number type, which is double by default), though you have the option to compile it to use a different number type instead. http:/
by haberman 16y ago
Same is true in Lua (only one number type, which is double by default), though you have the option to compile it to use a different number type instead.
http://www.lua.org/pil/2.3.html http://www.lua.org/pil/2.3.html
In particular, "long double" on x86 can represent 64 bit integers without loss as well as being floating-point (64 bit mantissa, 15 bit exponent, 1 bit sign). Downside is that it's quite large: 16 bytes.
- wnoise 16y agoThat's 10 bytes. Is it padded to 16 for alignment?
- haberman 16y agoYep. sizeof(long double) == 16, at least for me on gcc and Linux. Keep in mind that different compilers implement "long double" differently. According to Wikipedia, MSVC++ just makes it a synonym for "double," but most other compilers on x86 make it this 80-bit "extended precision" floating point.
- SAHChandler 16y agoWith MSVC on x86, you can pass /Qlong-double to the compiler for it to "properly size" the long double type :)
- silentbicycle 16y agoAlso, Lua has a couple bignum libraries available (a GMP wrapper, etc.) - it's explicitly noted in the manual that using doubles for Lua numbers by default is just a pragmatic trade-off, and they can be adapted as necessary.