[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.1 (beta) now available
- From: Mike Pall <mikelu-0511@...>
- Date: Fri, 18 Nov 2005 18:18:50 +0100
Hi,
Rici Lake wrote:
> > [In case anyone wonders: isnan() is only defined in C99.]
>
> I'm not convinced by this. (I agree with making the test explicit, just
> not with the avoidance of isnan()). isnan() is in POSIX (since Issue 3,
> it says here); furthermore, it has quite a long history of being
> implemented, including in all the IEEE-754 emulation libraries I've
> used. (It may require #include <ieee.h>, or some other non-standard
> header.)
There is no benefit from using isnan(). It's not inlined
(probably because nobody ever bothered) and it's slower.
Especially for the common case with a non-NaN operand.
> On the other hand, I've certainly seen C compilers (though I
> admit not for a long time) which would cheerfully optimize away the
> (a)!=(a) check (which certainly should be optimized away if a is an
> integer type.)
It's clearly a violation of the standard to optimize this
comparison away for floating point numbers. Abandon all
hope that such a compiler gets the other subtle issues
of FP arithmetic right.
BTW: At least gcc 3.x has no problems optimizing the integer
variant. Dito for the check for integerness (convert to int,
compare to original number -- see arrayindex, luaH_get). Maybe
this should be converted to an explicit macro, too. The integer
variants could then be defined to '0' or '1' which would help
less gifted compilers.
[LuaJIT has a highly optimized variant of the integerness test
in x86 assembler, but it's not easily reusable.]
Bye,
Mike