Search code examples
luasolar2d

Are hard-coded math operations performed at compile time or run time in lua


I know not all compilers do that but does lua do it?

I have this written 15 * 1.75 * 2 I can just leave a comment line and leave the calculation there, in order make it still understandable but leaving it like the way it is better and I am curious.


Solution

  • Math expressions are calculated at compile time in Lua 5.1+ (thanks to Luke100000 for the link in the comments).
    The only exceptions are infs and NaN. A Lua bytecode contains only finite numeric constants; "dangerous" math operations resulting in inf/NaN are deferred to runtime.