I use sqrt function on the number 500000. But the result I get is 707.10681152344 which is a bit inaccurate because the correct number should be 707.106781187 (as google and any other calculator gives). Why is that so? I may miss something as I am very new to LUA. Thanks a lot
The result you're seeing is consistent with 32-bit floating-point arithmetic.
Lua normally use 64-bit double-precision floating-point (corresponding to the C type double
), but according to this link:
It is easy to compile Lua so that it uses another type for numbers, such as longs or single-precision floats. This is particularly useful for platforms without hardware support for floating point. See the distribution for detailed instructions.
Apparently that's just the way the Lua implementation you're using was configured.