[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **RE: NaNs etc. once again. Was: Re: 5.1 and vc6**
**From**: "Thiago Bastos" <hellraider@...>
**Date**: Mon, 7 Mar 2005 00:13:56 -0300

Rici Lake wrote:
> But somehow:
>
> x = math.sqrt(math.atan(theta))
> if not x then
> -- oops an error
> end
>
> seems easier to explain and understand than either:
>
> if x ~= x then ..
>
> or
>
> if math.isnan(x) then ...
That is your opinion, of course, and I disagree.
I think "if math.isnan(x)" is much more straightforward to read.
For a C programmer, for example, the test "if not x" (x being a number)
could lead to the thought that Lua evaluates the number zero to false.
It could easily trick the novice in many ways.
The more you use implicit semantics, the more difficult your code gets to
read. In that respect, the "if not x" solution would be the worst.
Writing "if x ~= x" is, at least, less ambiguous.
-- Thiago