[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: NaN in Lua 5.3 Reference Manual
- From: "John Hind" <john.hind@...>
- Date: Fri, 23 Jun 2017 10:41:35 +0000
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.
First we have to face up to a logical incongruity: Not-a-Number (NaN)
*is* a number (type(0/0) == "number")! We probably just have to blame
the IEEE for that bit of stupidity (these standards committees!) and
face up to it instead of glossing over it.
The first reference to NaN occurs in 'Basic Concepts' (2.1) in the
description of the 'table' type: it is stated that, along with nil, NaN
is not a valid table key. Then in parenthesis "Not a Number is a special
value used to represent undefined or unrepresentable numerical results,
such as 0/0." Leaving aside this further logical incongruity (can one
represent the unrepresentable?), it would be clearer to give this
definition earlier, in the paragraph introducing the 'number' type.
Indeed the introduction of two number subtypes 'integer' and 'float'
opens up an opportunity for conceptual clarification. 'NaN' could be
presented as a third subtype. This would not necessarily imply an
implementation change, just a change in the way the concept is presented
in documentation and conceptualised by Lua users. Actually I think it
does in fact pretty accurately describe the current implementation.
Of course, for the next major release, changing the implementation of
math.type to return a third distinguished string key for NaN should be
considered. But this could be independent of changing the conceptual
representation in the Manual which could be done in a point release.