lua-users home
lua-l archive

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




On 16/07/16 12:15 PM, Philipp Janda wrote:
Am 16.07.2016 um 16:57 schröbte Soni L.:

On 15/07/16 08:05 PM, Tim Hill wrote:

— What is the type of the return value? It can’t be any existing Lua
type, since this is *already* used as the identity of a value of that
type. In other words, if __key returns (say) 100 as the key, then that
will collide with using the number 100 in the same table. Not good. In
fact, the only thing that __key could conceivably return would be
another userdata pointer. And if you analyze this carefully, you will
see if doesn’t buy you any functionality over what you already have.

Not good? If you have a bigint with value 100, any reasonable person
would expect it to be compatible with a plain Lua number with value 100,
just like how the plain Lua integer 100 is compatible with the plain Lua
float 100.0. If Lua numbers have this property, why shouldn't other things?

Doing the interning and equivalence class thing during construction of your bigints instead of during table indexing has the added advantage, that `100 == bigint(100)` works as well, that something like `table.insert({}, bigint(1), x)` works as well, and that it's probably also faster.

Philipp




And then you have bigint(2^62) + bigint(2^62) == bigint(-2^63)

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.