lua-users home
lua-l archive

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


2015-04-23 23:38 GMT+02:00 Franz Fellner <alpine.art.de@gmail.com>:
> Ross Berteig wrote:
>> One of the only reasons I've personally used floats for table keys has
>> been for memoization, where a table is used to cache results of (a
>> presumably expensive) calculation.
>
> IMHO even here using floats as keys is not a good idea:
>> x=1.1*1.1
>> y=1.21
>> print(x)
> 1.21
>> print(y)
> 1.21
>> print(x==y)
> false
>
> But probably it is OK for your use case. (And I know this isn't
> related to this whole thread).

It is possible to define __len for numbers to return a "fuzzy number"
for which `x ==# y` would be true. You could think of that as defining
fuzzy comparison operators `==#`, `<#` etc though of course it does
not lex that way.