lua-users home
lua-l archive

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




On Thu, May 9, 2019 at 8:20 AM Philippe Verdy <verdy_p@wanadoo.fr> wrote:
Why 8 ? this is even more confusive now...
If Lua numbers are implemented as IEEE 64-bit double-precision floatting points, you mean a number of bytes, but Lua numbers have no defined width/precision and even the datatype "double" in C is not necessary the IEEE 64-bit double (even if it's the most common one in today's computers, there are cases where it may be even 10,12 or 16 bytes if Lua numbers are implemented in C as "long double", but this is not in the IEEE standard, every C/C++ compiler may define it as it wants or to fit the underlying architecture or alignment constraints by adding padding bytes).

It's possible to integrate Lua with a host language that can process numbers with high precision (e.g. in Mathematica) and where number sizes could be much larger.

For 64-bit doubles, they have 18 significant decimal digits, and up to 3 digits for unsigned exponents; add the two possible signs, the exponent prefix and the decimal separator (suppose there's no grouping separator used), the common representation will not generate a string longer that 25 characters, plus up to 6 group separators in European/American locales. The length of that string is then bounded (from 1 to 32 at most, these strings cannot be empty, even for NaNs, infinites or denormals, and a Lua number cannot be nil because it's another type and there's no nil in IEEE 64-bit, just one or more NaNs). I see no other meaning for what would be the "length" of a number, because the length supposes a vector representation (as a string or in a sequence: what is them implied with "length" is the existence of an iterator for "elements" of numbers, and the common sense for these elements are characters).

Of course you could assume another base than 10 and get longer sequences, but a binary base makes no sense for floatting points (there just exists an alternate representation using hexadecimals, and a special "P" prefix instead of "E" for the base-16 exponent; there's less base-16 significant digits, so the malximum lenth of 32 will not be reached.

But do not confuse "length" (the concept for enumerating parts) with "size" (related to internal storage, something you never handle in Lua, except in networking or file API where you'll need a precise size in bytes or bits, and a bit-order, using an API-specific serializer)

Don't read too much into it. I wasn't being serious when I had made that comment.

I mean, I'm not serious about any of this, since it's really fairly meaningless to the overall Lua language, but as a mental exercise it's amusing. But the #n == 8 comment was never meant as anything more than a flippant remark.

/s/ Adam