lua-users home
lua-l archive

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

On Thu, Feb 28, 2013 at 12:35:55PM -0200, Jorge wrote:
> On 02/28/2013 06:35 AM, Egor Skriptunoff wrote:
> >On Thu, Feb 28, 2013 at 8:06 AM, Dirk Laurie <> wrote:
> >>x={}
> >>pi=math.pi
> >>for k=pi,20 do x[k]=k end
> >>print('{'..table.concat(x)..'}') --> {}
> >>print('{'..table.concat(x,',',pi,pi+5)..'}') --> ERROR
> >
> >Very nice example!
> >But anyway, I'm against adding "integer" data type to Lua. )))
> >
> Wait, that's no PI!
> An idea for a project: replace the fp in Luas number for a pair of
> integers, a and b, representing the fraction a/b. Define operations
> accordingly, and modify the parser.
> Jorge

So shall we ignore all the irrational numbers? No PI, sqrt(2), etc.?

I would welcome distinct number types (e.g., real, integer). But, if we must
use a single number type I would like it to work in the following manner. A
single number type would be comprised of 3 different types (C union?). If the
number can be represented as an integer, then it is an integer type. If the
number cannot be represented as an integer, then it is a real/double type. If
the number is too big for either an integer or a double, then it it a bignum
(i.e., arbitrary precision) type. From the lua programmers point of view, there
is only a single number type and the determination of what type of number it is
(e.g., integer, double, bignum) would be the responsibility of the VM as well
as the proper working of the operators (e.g., +,-,*,/,etc.) Though, I don't
know how easy or simple that would be implemented?

Christopher Berardi
May grace and peace be yours in abundance.