lua-users home
lua-l archive

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


On Fri, Jun 23, 2017 at 12:04 PM, John Hind <john.hind@zen.co.uk> wrote:
> In this case, I would reference IEEE 754 when 'float number' type is first
> introduced in section 2.1. I would then remove the reference to NaN from
> section 3.4.4. That leaves the issue of NaN not being a valid table key. Why
> not given it is a unique bit pattern in the IEEE 754 code space? But if it
> is necessary to specifically exclude it, I would refer to it as "the float
> number value NaN", or "the IEEE 754 value NaN".
>
> Presumably IEEE 754 positive and negative infinity ARE valid table keys,
> since they are not specifically excluded? What about positive and negative
> zero? Would these be distinguished table keys?
>
> The problem I had reading section 2.1 is that it implies 'NaN' is something
> like 'nil' (which as already been introduced) and never explains that it is
> actually a specific value of the float subtype of the number type.

It actually DOESN'T have a unique bit pattern in IEEE-754. All
IEEE-754 numbers with an exponent of all 1's is a NaN, and in fact
some VMs (including LuaJIT) exploit this fact to pack 52 bits of
useful information into the mantissa instead of storing it externally.

The reason section 2.1 doesn't mention IEEE-754 is because the Lua
reference interpreter doesn't rely strictly on IEEE-754 semantics
(notwithstanding the expected behavior of NaN) and it will compile and
run just fine on platforms that use other floating-point
representations (this is mentioned in 3.4.1).

I'm pretty sure you're right that positive and negative infinities are
distinct table keys. I don't think positive and negative zeroes are
because they compare equal to each other in all contexts.

As for referring to it as "the float number value NaN" in section 2.1
-- it already does. The parenthetical note right there calls out that
it is a special value used as a numerical result.

As for removing it from 3.4.4... Why? This definition is actually
required BECAUSE Lua doesn't require that the underlying platform
supports IEEE-754 semantics, but the language guarantees these
semantics anyway. (Also, there are other languages that use IEEE-754
floating point math that give NaN a well-defined comparison value in
order to provide a well-ordering property over the set of all possible
values.)

/s/ Adam