[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lnum* patches
- From: Sam Roberts <sroberts@...>
- Date: Tue, 29 Aug 2006 16:07:08 -0700
On Wed, Aug 30, 2006 at 12:42:40AM +0300, Asko Kauppi wrote:
> This is a proof of concept, but for people needing to run Lua 5.1 on
> non-FPU platforms, it is already worth a try. API's etc. have
> remained; this should be 100% backward compatible with Lua.
Asko describes and uses this as an optimization for non-FPU platforms,
but its much more useful than that.
What these patches do internally is add a second basic lua number type,
INTEGER, allowing the size of lua_Number to vary between float and
double, and lua_Integer to vary across int32 and int64, independently of
each other.
>From lua code this fact is pretty much hidden. Numbers that aren't
naturally float in the code (0.2) internally are created as type
INTEGER instead of number. Its also pretty transparent from C code, if
you call lua_tointeger() you'll get64 bit integers without loss of
precision if they were ints, and by conversion from lua_Number if
necessary. Similarly if you call lua_tonumber() either the NUMBER
(usually float/double) or the INTEGER value will be converted to the
desired type, lua_Number. Mixed INTEGER and NUMBER arithmetic converts
as necessary, promoting to NUMBER (float) as necessary.
Its not for everybody, perhaps, but its very handy for those who need
wider integers than can fit into a double.
I would like to hear a discussion about how the lua core can have some
of its assumptions about numbers loosened so that new number disciplines
like this can be implemented with minimal patching (preferably, none!)
of the core code, much as other aspects of lua are now customizable in
the build environment through macros, and selective redefinition of
specific functions.
Cheers,
Sam