[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [NoW] Inf-phobia of Lua bytecode
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 10 Jul 2019 17:39:16 -0300
> I've noticed that Lua never stores floating point values inf, nan, -0.0 in
> bytecode (in table of constants).
> local x = 5/4 -- constant 1.25 due to constant folding.
> local y = 1/0 -- constants 0, 1 and DIV instruction.
> local z = -0.0 -- constant 0.0 and UNM instruction.
> It seems that Lua intentionally defers possible FP errors until run-time.
> Why such approach was implemented?
It is simpler and safer, and we don't think those constants are common
in performance-critical code.
NaN and -0 have problems with the unification of constants used by the
compiler: NaN is not equal to NaN, while -0 is equal to 0.
Moreoever, if needed, it is easy to redefine the macro luai_numdiv
to raise a Lua error for a zero denominator (for an hypothetical
architecture that could crash with that operation). So, we avoid
doing that operation during compile time.