lua-users home
lua-l archive

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


On Wed, Aug 03, 2011 at 10:38:40PM +0200, Norman Ramsey wrote:
> I liked the story about 'all numbers are IEEE doubles', but it 
> sounds like the real story is 'all numbers are IEEE doubles, 
> except when they are cast to C ints.'   That's not nearly as good.
> 
The real story is: "Lua has no integer type, as it does not need it.
… a Lua number can represent any long integer without rounding problems."
(PiL, §2.3).  Sounds good to me.

> Is there any chance that the new manual for 5.2 can list explicitly
> every place that a Lua number is coerced to a C int?  So far I know
> about certain arguments to string.format and about string indices.  
>
Not only would that be a great amount of work for the authors, work
moreover of the kind enjoyed by compilers of concordances rather than
creative programmers, but it would change a document that "is dry in 
places" to one that is indigestible.  

All it takes to make sense of the way Lua handles integers is a
combination of common sense and goodwill.  Do you have strings of
length more than 2^32?  (That's 4 terabytes.)  Of course you don't.

A friend of mine told a student of his who claimed to have misunderstood 
an exam question because it was phrased ambiguously: "Don't be a twit.
The question can be read in only one way."  But I'm a polite guy, I 
would never say something like that.

> I assume that general table indices are *not* converted to ints.  
> But it would be good to have the information written down...
> 
No need to assume, that item of information _is_ written down.  Tables can
be indexed "with any Lua value except nil and NaN"  (5.2 manual, §2.1).

Dirk