lua-users home
lua-l archive

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


This would be also my favorite solution, having two independent number types. My software floating point emulation slows down the execution unacceptable, but I need double numbers to make use of LuaOrb. I am just in the process of doing an implementation of integer numbers through tag methods on userdata, but I wonder what will be the costs of it compared with a direct long number type. 
Ralf

>>> john@glowingslab.com 04/18/00 10:17am >>>
If there are only a few, well-known changes that are required to enable Lua
to use longs, why don't you change the main source code to support it
automatically?  Sounds like you could apply the changes you mention with a
few #defines/#ifdefs.

I expect that if you added explicit support for "float" and "long", you'd
cover the vast majority of people who wanted a different number type.  And
it would save you having to write a technical note!  :-)

john

-----Original Message-----
From: Luiz Henrique de Figueiredo To: Multiple recipients of list
<lua-l@tecgraf.puc-rio.br>
Date: 17 April 2000 17:26
Subject: Re: number question


>>From: "Ralf HECKHAUSEN" <RHeckhau@frequentis.com>
>
>>We want to run Lua on an machine without floating-point-unit and basically
only need integer numbers. How much effort is it to switch the number type
to long instead of double?
>
>Not much effort really.
>The simplest solution is just to choose -DLUA_NUM_TYPE=long in config.
>This should compile without problems, although it will still %g in sprintf
>for converting numbers to string.
>Moreover, the lexer will still use floating-point arithmetic to read
numbers
>from Lua programs.
>If you really want *no* floating-point arithmetic at all, then you need to
go
>through the code and look for all places marked "LUA_NUMBER" and then
remove
>the floating-point arithmetic.
>For Lua 3.2, these places are:
>
> lobject.c:double luaO_str2d (char *s) {  /* LUA_NUMBER */
> lvm.c:int luaV_tonumber (TObject *obj) {  /* LUA_NUMBER */
> lvm.c:int luaV_tostring (TObject *obj) {  /* LUA_NUMBER */
> lundump.h:#define NUMBER_FMT      "%.16g"         /* LUA_NUMBER */
>
>plus the "fraction:" loop in llex.c.
>You may want to change the API to use longs intead of doubles too.
>
> lapi.c:double lua_getnumber (lua_Object object)
> lapi.c:void lua_pushnumber (double n)
> lauxlib.c:double luaL_check_number (int numArg)
> lauxlib.c:double luaL_opt_number (int numArg, double def)
>
>and the corresponding declarations in lua.h and lauxlib.h.
>
>I plan to write a Lua Technical Note about this when I find the time.
>
>>Is it possible to have a new user type float next to number with all
standard operators? Did someone already implement this?
>
>You could implement those using tag methods on userdata.
>--lhf
>