lua-users home
lua-l archive

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


Op So., 26 Aug. 2018 om 05:29 het Egor Skriptunoff
<egor.skriptunoff@gmail.com> geskryf:
>
> 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.

This seems to imply that it is perfectly OK to return any value from 0
to 4566 for 0x1p1000%4567, instead of the correct value 4567 that Lua
5.3 returns. Correct-shmorrect, I say.