[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Comparison operators (Was: Numeric key collision related bug in Lua 5.3)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 24 Apr 2015 10:07:30 +0200
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.