[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua 5.1 (alpha) now available
- From: Mike Pall <mikelu-0509@...>
- Date: Sat, 3 Sep 2005 14:27:06 +0200
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
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.