[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modulo infinity
- From: Dirk Laurie <dirk.laurie@...>
- Date: Mon, 31 Mar 2014 22:18:19 +0200
2014-03-31 20:49 GMT+02:00 Egor Skriptunoff <egor.skriptunoff@gmail.com>:
> On Sun, Mar 30, 2014 at 6:10 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>>
>> 2014-03-30 14:19 GMT+02:00 Egor Skriptunoff <egor.skriptunoff@gmail.com>:
>> > Mathematically, for any finite non-negative number N
>> > N % math.huge == N
>> > But this equation does not hold in Lua.
>> Because math.huge is not a finite non-negative integer. The result
>> NaN is, correctly, standard on any IEEE 754 compliant hardware.
> NaN is NOT a correct answer for N%inf.
> Just check this code in your favorite C compiler:
> http://codepad.org/ebn79KuY
That code does not calculate N%inf. It calculates fmod(x,Inf).
C does not allow N%inf because % is for integers only and inf
is only available as float/double.
> Both underlying hardware (FPU) and C libraries work with infinity in a
> consistent way whenever possible.
> It is Lua that breaks this consistency.
> It can be improved by changing the formula used by Lua to calculate modulo.
Lua breaks no consistency. You want fmod? Lua has it. In the math library.
It gives the same result as in C. It should, since it actually calls
the C function.
But fmod is not %. You can argue that Lua should throw an error for N%inf,
as C does, and I may even support you. But Lua should not quietly give
N for N%inf. Giving NaN is a good compromise.