lua-users home
lua-l archive

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


> This means that code such as:
> 
>     t = { }
>     t [ 0.0 ] = "foo"
>     for k , v in pairs ( t ) do
>         t [ k+2^65 ] = v
>     end
> 
> Will completely change behaviour.

Sure. You would have to change 2^65 to 2.0^65 to have back the original
behafior.


> Though this is an esoteric example, I can brainstorm several manners in
> which this behaviour could sneak into my modules.

This is quite esoteric indeed. I would like to hear about more realistic
cases.


> A 'solution' to this 'problem' is actually a bit hard to think up, I don't
> think wrap around is the behaviour that should happen here.
> Intuition tells me a silent promotion to double might be the best choice;
> but this might not make sense when you're not on a 64/64 build.

In my view, it does not make sense in a 64/64 build either. The problem
is that 64 bits are not enough to represent an integer, then you change
it to 53 bits as a solution? Just to mention your esoteric example,
all keys 'k' from 1 to 2e12 would collapse to the same value when
it computes 'k+2.0^65'.

The only sensible alternative I see is to raise an error; it is not easy
to choose what is best.

-- Roberto