lua-users home
lua-l archive

Re: Modulo infinity

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


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

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.

Correct FP operations with infinity will reduce number of "if"s in your program and will make your code more clear.

AltStyle によって変換されたページ (->オリジナル) /