[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Integer-Only Lua
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 25 Sep 2000 21:14:11 -0300 (EST)
>One of the things I would really like to see in Lua is the ability to make
>numbers purely integer. Right now, you can tell the compiler
>-DLUA_NUM_TYPE=long and that would do most of the job.
>But it doesn't go far enough.
More precisely, it does use long for the numbers, but still accepts floating
point numbers in the lexer and still uses a %g format for conversion to string.
The second point is easily changed to %ld and removing a cast to double.
The first point is more subtle because it does change the language a little,
but otherwise it's just as easy to change.
>I would appreciate anyone who has done a floatingpointectomy to Lua 4.0
>alpha to point out if there are any subtle areas to look out for. The
>sprintf() in lvm.c is pretty obvious, but I'm guessing there might be
>others lurking.
All places that might need to be changed are marked in the code with LUA_NUMBER.
In 4.0b, these are the only places:
% grep LUA_NUMBER *.[ch]
liolib.c: if (lua_type(L, arg)[2] == 'm') { /* nuMber? */ /* LUA_NUMBER */
llex.c:/* LUA_NUMBER */
llimits.h:** GREP LUA_NUMBER to change that
lobject.c:int luaO_str2d (const char *s, Number *result) { /* LUA_NUMBER */
lundump.h:#define NUMBER_FMT "%.16g" /* LUA_NUMBER */
lvm.c:int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
lvm.c:int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */
>Maybe Lua 4.0 beta addresses this-- maybe not. I haven't looked at it yet.
>But I do want to state that I'll bet there are a number of Lua users who
>don't use floating point at all in their applications, and would enjoy not
>having the implicit dependencies on floating point there. And if for no
>other reason, having a mode to compile Lua in integer-only mode would make
>the already screaming VM even more insanely fast.
I'll try to add a Lua script in the final distribution that changes the code to
integer-only.
--lhf