lua-users home
lua-l archive

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

On 6-Mar-05, at 6:36 PM, Shannon Stewman wrote:

Your first suggestion would make it hard to track down dumb bugs in
numerical code.

That depends on how the arithmetic operations responded to receiving
a nil / NaN. Indeed, both of them could throw an error. Or both of
them could do pass through. In fact, making NaN test false makes it
easier to test for dumb bugs: you just throw an assert around your
arithmetic computations.

The whole point of NaNs was to avoid having to do a whole bunch of
tests on a complicated arithmetic expression; the intention was never
that the result would not be tested. There was also the desire to
avoid having to serialise computations which could be done in parallel.
It's not actually clear to me that a scripting language should
even preserve NaN behaviour rather than simply returning an immediate
error, but if a programmer were conscientious about checking, that
might get in the way.

So I'd be ok with NaN's being checked for by Lua, but the alternative
of letting me use assert rather than some mysterious and possibly
non-functional self-inequality check seems more pleasant.

  The presence of NaN usually tells me one of two

1. I divided by zero somewhere

That will give you +/- infinity unless you divided 0 by 0

2. I gave a function an invalid number (e.g., took the square root of
   an negative number)