lua-users home
lua-l archive

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

> I ran the full lua 5.3.3 tests with the latest gcc (6.2.0) and clang
> (3.8.0) sanitizers.
> Issues that came up were all divisions by zero:
> lvm.c:936:11: runtime error: division by zero
> Triggered with `1/0`
> lvm.c:1016:11: runtime error: division by zero
> Triggered with `1//0.0`
> lobject.c:109:28: runtime error: division by zero
> This is from the test in api.lua `assert(T.testC("arith /; return 1",
> 2, 0) == 10.0/0)`
> Btw, the lack of an accompanying error for arith with LUA_OPIDIV
> suggests a missing potential test :)
> These all boil down to use of the `luai_numdiv` macro:
> #define luai_numdiv(L,a,b)      ((a)/(b))
> I guess the fix would be to check for b == 0 before performing the calculation?

Last time I checked, in all machines that implement the IEEE standard
(that seems to be all machines), a float division by zero was a valid
operation, which may result in -inf, inf, or NaN. We try to follow
the IEEE standard as much as possible (in other words, we try to not
interfere with it). If there was a test for (b == 0), what should it do
in a positive case?

-- Roberto