lua-users home
lua-l archive

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


On Sat, Jun 15, 2019 at 3:25 PM Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> It's not so much the platform as what future compiler versions may do.
> These divisions by 0 are nasal-demon situations.

Can you be more specific? I always learned that division by 0 in IEEE
floats was something well defined and well behaved. Most compilers
try not to interfere with IEEE semantics.

-- Roberto


The well-defined semantics of division by zero are part of Annex F of the C specification, which is an optional thing that compilers are not required to implement. In the absence of Annex F, division by zero has undefined behavior. C++ doesn't have anything like Annex F and division by zero is stated to be undefined (although they mention in a non-normative comment that most implementations allow the behavior to be controlled using library functions).

A division by zero could result in a trap, exception, or signal such as SIGFPE. The convention has been to move away from those behaviors because it's convenient to use 1.0/0 as a way to get infinity, but unless Lua's documentation specifically requires that you don't do that, nothing stops you from passing a compiler flag or calling a library function to change that.

/s/ Adam