[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: NaN in Lua 5.3 Reference Manual
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 23 Jun 2017 16:39:22 +0200
2017-06-23 12:41 GMT+02:00 John Hind <john.hind@zen.co.uk>:
> I notice that Lua 5.3 Reference Manual has been extensively edited over the
> last few point releases, but one aspect that is still not very well
> described is NaN. There are three references to it, all tangential. Two
> state that it is not a valid table key while the third describes its
> treatment by comparison operators. The thing itself is never properly
> introduced.
NaN is an IEEE-754 subtlety and no more worthy of elaboration in
the Lua manual than a discussion of why n*(1/n)==1 might for some
values of n be false. The properties mentioned in the manual are
precisely the ways in which it impinges on essential Lua issues.
It does fall within the scope of an auxiliary glossary [1] for careful readers,
and there I wrote the following:
NaN
---
Acronym for "Not A Number". An exceptional value of type [number] (also
written 'NAN' and 'nan'), which arises as the result of an undefinable
arithmetic [operation]. NaN is not a Lua keyword, but appears in
output (in some implementations, even the nonsensical '-nan' may
be printed). If you need the notation NaN, assign such
a value to the name.
NaN is not a legal [key] in a table, but counts as [true](truth).
NaN = 0/0
NaN + 1 -- NaN. All arithmetic operations involving NaN have
-- result NaN.
NaN <= NaN -- false. All comparison operations involving NaN have
-- result false except the following.
NaN ~= NaN -- true. The only Lua value with this property.
[1] https://rawgit.com/dlaurie/lua-notes/master/glossary.html