[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Numeric key collision related bug in Lua 5.3**
**From**: Roberto Ierusalimschy <roberto@...>
**Date**: Thu, 23 Apr 2015 04:59:42 -0300

> What about relational operators? Consider this:
>
> a = (1<<60) + 180
> b = (1<<60) + 200
> bf = b + 0.0
> print(a < b) -> true
> print(a < bf) -> false (!)
> printf(a < math.tointeger(bf)) -> true
>
> Of course, I carefully chose those numbers, but the truncating effect of integer->float will give strange results when doing (say) table.sort() on mixes of floats and integers.
That is true, but I think this is a "smaller" problem for several reasons:
- table.sort is strongly associated with "<", so it seems more
reasonable to get "strange" results when "<" is strange.
- You can set your own order method if you want a different comparsion.
- We already have "strange" results if the table has NaNs or if you
provide an inconsistent comparsion function.
Morever, I guess (but may be wrong) that a better comparsion function
(e.g., that compares the "true" mathematical values) would be
expensive. Unlike equality, that we seldom use for floats, mixed order
comparisons can be quite frequent (e.g., "if f > 0 then" instead of
"if f > 0.0 then"), so we do not want something expensive here.
-- Roberto