lua-users home
lua-l archive

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


Hi,

Wim Couwenberg wrote:
> I wonder if the same trick works for big endian IEEE 754 based
> architectures if we adjust it like so:

I guess it would. But why bother? All CPUs other than x86 have
a decent FP instruction set (x87 FP is _not_ decent). And these
usually provide both a 'truncate FP to integer' and a 'round FP
to integer' mode without undue performance penalties.

The real problem behind this is the C standard which mandates
that a cast from doubles to int does truncation and not rounding.
The former requires a (slow) FPU mode switch for the plain x87 FP
instruction set.

But it doesn't matter for the few occasions Lua needs this.
So rounding would be ok, too. Alas, there is no way to specify
this with C89. And lrint() from C99 is slow if not inlined.

Bye,
     Mike