lua-users home
lua-l archive

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

On 21 Feb 2011, at 18:37, Dirk Laurie wrote:
   (a) NaN is to numbers what nil is to Lua values: not-a-number vs
not-a-value. It makes intuitive sense that it should be logically
       different from numbers.

OK, but why this implies NaN should evaluate to false? Apparently, Lua authors regret that nil evaluates to false [1]: "Not introducing booleans from the start had a few unfortunate side-effects. One is that we now have two false values: nil and false.". Lately, I've become a little more inclined to agree with them in this particular aspect because I seems to me it brings more confusion than actual benefits.

   (b) The implementation, as Tony has shown, requires a minimal
       change to the Lua source code.

Most times, the implementation is the easiest part. A harder part is to reason about all the subtle implications of these apparently innocent changes.

   (c) It would allow elegant error-checking code like
x=assert(x-f(x)/df(x), "NaN in Newton iteration, maybe a multiple zero?")

If you want to check for NaN or nil, why not doing it explicitly:

function assertnumber(value, ....)
	if type(value) ~= "number" or value ~= value then
	return value, ....


Renato Maia
Computer Scientist