[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua number type and 64-bit machines
- From: Mike Pall <mikelu-0903@...>
- Date: Fri, 6 Mar 2009 18:03:12 +0100
Luiz Henrique de Figueiredo wrote:
> Anyway, one answer the original question is that Lua already supports
> long doubles in 64-bit machines, just not automatically: you need to change
> a few lines in luaconf.h. But you'll want to know how your compiler handles
> long doubles.
Not a good advice. Having a 64 bit CPU means that it has a 64 bit
address space and good support for 64 bit *integers*.
This does *not* imply that there is support for a suitable "long
double" type. The support is just as bad as on 32 bit CPUs.
1. "long double" can mean anything, depending on the compiler.
E.g. MSVC maps it simply to "double". Support in other compilers
and standard libraries is rather weak.
2. It's very non-standard what kind of underlying FP data type you
get. The x87 FPU uses an 80 bit format. Some use an 128 bit
format. Other CPUs use an aggregate of two appropriately scaled
doubles. Most CPUs have no hardware support for this at all.
3. Even with the x87 FPU it depends on the rounding mode whether
you really get the 64 bits of precision in the mantissa. E.g.
under Windows it's by default set to 53 bits.
4. Since all x64 CPUs have SSE2, the x87 FPU is not used for FP
calculations by default. Interacting with other functions using
the regular "double" FP type involves rounding, must go through
memory and is generally slow.
5. The x87 operations to load/store the 80 bit data type are
really slow.
Using the "long double" data type just to hold 64 bit integer data
is not a good idea. You're slowing down the whole Lua interpreter
and asking for trouble with extension modules.
--Mike