lua-users home
lua-l archive

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


On 9 June 2015 at 23:54, Rena <hyperhacker@gmail.com> wrote:
> On Tue, Jun 9, 2015 at 3:12 PM, Dibyendu Majumdar
>> I overlay the double with the type code.
>>
>> So the structure looks like this:
>>
>> |------ first 8 bytes ----------| |------- second 8 bytes -------|
>>   value other than double        type code (int) union
>>   including 64-bit int                 with double
>>
>> Since the size of the value object is 16 bytes anyway it doesn't
>> change the overall size.
>>
>
> Isn't this basically the "NaN trick" that some versions of Lua used?
> If the value is NaN, certain bits encode type information; otherwise
> it's a double?
>

Yes.

LuaJIT uses a single double type - so everything is overlayed onto
that. Limitation is that integers must be 32-bits.

What I have described above is a less efficient implementation as it
preserves the 64-bit int so the value object takes up 16 bytes (which
is incidentally what the value object takes up anyway due to padding).

Sadly performance wise it doesn't seem to help :-(

Regards