lua-users home
lua-l archive

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


> 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.

-- Roberto