lua-users home
lua-l archive

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


> On Apr 22, 2015, at 9:13 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> 
> 
> My guess is that the best sollution would be to change the definition
> of equality (to a simpler one :-). Two numbers should be considered
> equal if they represent the same mathematic value; period. (In terms
> of implementation, it means that integer-float should be compared
> converting the float to an integer; if the conversion fails, the numbers
> cannot be equal.) That definition is simple, sounds sensible and
> easy to explain, and makes equality transitive.
> 
> -- Roberto
> 

+1, for all the reasons you state.

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.

—Tim