lua-users home
lua-l archive

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


Hi,

Bogdan Marinescu wrote:
>     Sorry if this was answered before, I was unable to find the answer
> in the archives. I wonder what is the relation between LUA_NUMBER and
> LUA_UACNUMBER.

LUA_UACNUMBER should be set to the 'usual argument conversion' for
LUA_NUMBER. Unfortunately C performs some implicit typecasts when passing
arguments. The common case is that floats get promoted to doubles.
And this is the only case to really worry about (you can't use chars or
shorts anyway). In all other cases use: #define LUA_UACNUMBER LUA_NUMBER

> I tried to compile a LUA integer version on Win32, and
> it worked when I defined LUA_NUMBER as "long" and LUA_UACNUMBER as
> "long long".

This does not do what you want. When you want 32 bit numbers define
LUA_NUMBER to 'int' on 32 bit or 64 bit platforms and to 'long' on
16 bit platforms ('long' is possible on 32 bit platforms, too).

> When I defined both LUA_NUMBER and LUA_UACNUMBER as
> "long", the factorial test (test/factorial.lua) failed.

That's because 16! = 20922789888000 and this number does not fit in 32 bit.
The highest factorial that should work is 12! = 479001600. I.e. the behaviour
is expected (silent overflow).

BTW: I think we should put up a Wiki page that lists all possibilities for
     setting LUA_NUMBER and what defines you have to tweak depending on
     the Lua version. Any volunteers?

Bye,
     Mike