lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I think the main problem with using floating point as the only numeric type in lua is: most programmers do not understand floating point. After all, it is A LOT more complicated than integer. I think most programmer's mental model of floating point is: sometimes the result of an operation is very slightly wrong. As a consequence, people get jittery.

The solution to this problem is education. I think the essential integer-backwards-compatible behavior of double floating point should be emphasized more in the documentation, the website, the faq, the wiki, etc. This question is often raised on this forum and I'm sure for every vocal person with doubts many lurkers are similarly nervous.



If you have a normal modern desktop computer, then you have IEEE 754 floating point, double precision.

Some points about (IEEE 754) 64-bit double floating point VS 32-bit ints:

*  double can represent many more integers exactly
*  in fact, everything int can represent, double can represent, exactly
* every result that integer arithmetic can compute correctly and exactly, double arithmetic can compute correctly and exactly * largest power of ten: a 64-bit double can represent all integers exactly, up to: 1,000,000,000,000,000 (actually -2^53...+2^53) * largest power of ten: a 32-bit int can represent all integers exactly, up to: 1,000,000,000 (actually -2^32...+2^32-1)

Regarding performance, most serious modern desktop CPUs these days can process double floating point as fast as or faster than integer. Eg modern MIPS, modern PPC, and better. Intel: poor third (too few FP registers). For users of these CPUs the only major remaining potential issues are memory bandwidth, memory usage. Am I right in thinking that because of the cell size, these considerations are actually irrelevant in lua?

There are users of older or smaller or embedded CPUs who have no floating point, or no 64-bit floating point, or CPU emulated floating point, or slow hardware floating point. E.g. 80386, 68040, ARM, etc. I guess the config feature mostly fills their needs.

Martin.