lua-users home
lua-l archive

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



Hi, everyone.

I'd like to initiate discussion about number modes in Lua. It's sometimes seen on the list that people find it hard to change the default number types (they can be changed in Lua, but not all implications are in the luaconf.h file). I'd like to ask, which _needs_ people have to change the type, and which would be the best set of number modes to answer such needs.

My experience below, but first a short summary to those not familiar with LNUM patch.

LNUM patch enables integer mode number optimizations, without changing the existing Lua scripting or C API interfaces. It allows moderate to huge speed increases, depending on the system. It also makes it easy to change number modes between any combination of: float / double / long double, 32/64-bit integers, optional complex arithmetics.

The LNUM patch is now ready and tested for Lua 5.1.3, and I'd like to get feedback on how people actually use it, as well as to bring out some complexities found in making it.


To start the discussion, here's my feelings about usefulness of various number modes:

LNUM_DOUBLE + LNUM_INT32: Useful as a default, absolutely ANSI C. No portability issues.

LNUM_INT64 Useful, and rather portable though 'long long' is not ANSI C. The added integer precision should be valuable (double only has 50+ bits).

LNUM_FLOAT Problematic. Math functions not ANSI C. Limited or no support on Windows. The only benefit I see is less memory consumption on embedded devices (speedwise, not much difference with LNUM_DOUBLE+LNUM_INT32). Is anyone actually using 'float' currently, and what is the main reason you do?

LNUM_LDOUBLE	Problematic. Not ANSI C, limited or no support on Windows.
I've hit a few weird behaviours on Lua 5.1.3 when lua_Number is defined as 'long double'. OS X Intel crashes; Linux x86 gives stack warnings. The reason for these is unsolved; is someone actually using (unpatched) Lua 5.1.3 with 'long double' on such systems? On other systems (OS X PowerPC, Windows XP) long double seems to work fine.

LNUM_COMPLEX It's neat, and it works (with any number mode). Surprisingly little portability issues, but it does require C99.

-asko


News I placed to LuaForge:	http://luaforge.net/forum/forum.php?forum_id=1582
Download the patch / performance sheet:	http://luaforge.net/frs/?group_id=214