lua-users home
lua-l archive

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


On Sat, Aug 25, 2018 at 8:28 PM, Egor Skriptunoff wrote:
Correct modulo operation is not very simple


I should clarify what is the "correct modulo".

Rounding errors are inevitable, so instead of exact result
   a%b
you are allowed to return
   approx( approx(a) % approx(b) )
Each approx() might modify low bits (bits beyond FP precision).
You are not allowed to return arbitrary garbage (such as negative value for positive b).

In other words, you must return a value which belongs to possible result range according to interval arithmetic.

Of course, the same requirement applies to all math operations and functions, not only modulo.