lua-users home
lua-l archive

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


As someone with little math background it seem logical that the language should have a built in test for this as the implementation details of testing for NaN are outside the scope of most people's understanding, yet it is something that is important to test for. This train of thought would support Mr. Hinds argument that it should be considered a numerical subtype that would return a distinguished value. 

if type(x) ~= 'nan' then
...
end

Russ

Sent from my BlackBerry 10 smartphone on the Virgin Mobile network.
From: Enrique Garcia Cota
Sent: Saturday, June 24, 2017 4:01 AM
To: John Hind; Lua mailing list
Reply To: Lua mailing list
Subject: Re: NaN in Lua 5.3 Reference Manual

Hi,

The (odd) requirement of the IEEE standard that NaN not test equal to itself means that there is no (robust) way to test for NaN from Lua

Wouldn't this be enough?

    function isNan(x)
      return x ~= x
    end

Or if you want something a bit more resistant against tables with metatable magic:

    function isNan(x)
      return type(x) == 'number' and x ~= x
    end