lua-users home
lua-l archive

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


On Mon, Jun 8, 2015 at 10:16 PM, Coda Highland <chighland@gmail.com> wrote:
On Mon, Jun 8, 2015 at 12:15 PM, Brigham Toskin <brighamtoskin@gmail.com> wrote:
> On Mon, Jun 8, 2015 at 12:12 PM, Roberto Ierusalimschy
> <roberto@inf.puc-rio.br> wrote:
>>
>> > > By the way, there is a single case of wrong comparison with NaN:
>> > > print(1<<63 <= 0/0)  --> true
>> > > It is hardly dangerous, just curious (I'm not proposing to fix it).
>> >
>> > Thanks for the report. (Of course it must be fixed; it is a bug.)
>>
>> (And it can be "dangerous": it is converting NaN to integer, which
>> can trap on some machines.)
>
> Not to mention any code that depends on the semantics of comparisons with
> NaN will break.
>
Which is slightly less theoretical than it might seem, as Lua values
are supposed to have a total ordering.

This bug is occured only with the number 1<<63 (which is MIN_INTEGER).
But whole usual math breaks on this number:
x < 0 and (-x) < 0 simultaneously
x - 1 > x
2*x == 0
In such context, wrong comparison with NaN is not a big problem at all :-)

Using a language with arbitrary precision integers would be less error-prone
compared to a language with traditional "wrap around" math.