lua-users home
lua-l archive

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


On Wed, 2009-06-10 at 12:52 -0300, Roberto Ierusalimschy wrote:
> > I ran into a 32/64 bit problem yesterday.  I need to compute a big
> > integer (basically by multiplying with 2^40), and I only need it in a
> > string representation (i.e. no further arithmetic on the result).  The
> > naive approach results in a floating point representation:
> > tostring(4095 * 2^40) => 4.5025001157427e+15
> > 
> > On 64 bit, the following works:
> > ('%d'):format(4095*2^40) => 4502500115742720
> > 
> > but on 32 bit I get:
> > ('%d'):format(4095*2^40) => -2147483648
> > 
> > I solved this by using BitNum.lua, but still have some questions:
> > 1) Why is there no support for '%ld'?
> 
> There is (see LUA_INTFRMLEN in luaconf.h). Probably your system has
> sizeof(long) = 4, so you actually needs '%lld' which is not ANSI C 89.
> Define LUA_USELONGLONG to compile Lua using long longs.

Code should run on a stock 32bit Ubuntu/Debian lua, and that does not
seem to have LUA_USELONGLONG defined.  Will ask maintainer about that.

Also: Is there any way to figure that out (e.g. what is the value of
LUA_INTFRMLEN) from within a plain lua script?

</nk>