lua-users home
lua-l archive

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


On Fri, Mar 01, 2013 at 11:43:54AM +1100, Daurnimator wrote:
> On 1 March 2013 09:40, Christopher Berardi <cberardi@natoufa.com> wrote:
> > 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.
> >
> 
> That's pretty much what ruby does.
> One of the main reasons we don't do this in lua is the size of a
> bignum library: AFAIK it's likely to massively increase the size of
> the lua source.

Actually, it has been done in less than 10% of the current size of Lua 5.2*.

The axTLS project has a bignum library in a single ~1500LoC^ file supporting
addition, subtraction, multiplication, and division.

	http://axtls.sourceforge.net/

The author even implemented Karatsuba multiplication. If you removed all the
duplicative optimizations, it'd be smaller, still.


* 16450 for `cat lua-5.2.1/src/*.c | wc -l`
^ 1512 for `wc -l axTLS/crypto/bigint.c`