lua-users home
lua-l archive

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


On 25/11/2012 04:52, Dirk Laurie wrote:
I have an idea.
Strings can be treated as integer numbers of arbitrary length.
So, a string of length 8 can be used instead of 64-bit integer.
Let all integer and bitwise operations be implemented on strings.
Strings will never overflow because of auto growing up.
It will be cool to have very-long-integer arithmetic in Lua
without external libraries.


implementing a BCD-like solution without optimizing per
arch is pretty much useless in the face of competition (gmp,
openssl bn, cobol itself). serious projects would end up
using external libraries anyway

I haven't checked Python's source code but I would be very sup

Wim Couwenberg's GMP binding allows strings-as-long-integers with
very little extra work.  Except for one thing: automatic coercion.

gmp=require"gmp"
getmetatable"".__pow = function (x,y)
     print "metamethod called!"
     return tostring(gmp.z(x)^y)
end

print ("11"^"100")
1.3780612339822e+104

So you need to fool Lua but not GMP.

print ("1 1"^100)
metamethod called!
137806123398222701841183371720896367762643312000384664331464775521549852095523076769401159497458526446001

Very interesting (and cool;-)

Denis