lua-users home
lua-l archive

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

On Thu, Apr 23, 2015 at 10:59 AM, Roberto Ierusalimschy <> wrote:
> What about relational operators?
> 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.

Yes, we have strange results when sorting tables with NaNs inside.
But we don't have errors there.
Is it possible to receive "invalid order function for sorting" error for
default sorting (using default order function) of a table filled with mixed
integer/float values due to non-transitivity of default operator ">="?

Transitivity of equality and relational operators sits very deep in our brains.
A language without such transitivity would be counter-intuitive,
programming on it would be error-prone.

IMHO, if both numbers are inside range 2^53...2^63, they should be compared
using conversion to integers, despite of possible performance penalty.