lua-users home
lua-l archive

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


> > Has anyone already tried to compile Lua with lua_Number defined as the
> > "long double" C data type?
> 
> These changes in luaconf.h seem to work fine with "make ansi".
> 
> #define LUA_NUMBER	long double
> #define LUA_NUMBER_SCAN		"%Lf"
> #define LUA_NUMBER_FMT		"%.14Lg"
> 
> I've used ansi to avoid the integer conversion tricks, which are specific to
> doubles, I guess.

With a few more changes, Lua seems to work fine with 64 bits:

> x=0xffffffffffffffff
> =string.format("%x", x)
ffffffffffffffff
> = x == bit32.NOT(0)
true
> =string.format("%x", bit32.SHR(x, 4))
fffffffffffffff
> return string.format("%16x", bit32.SHR(x, -4))
fffffffffffffff0
> return string.format("%016x", bit32.SHR(x, 4))
0fffffffffffffff
> x=0x123456789abcdef
> return string.format("%016x", x)
0123456789abcdef
> return string.format("%016x", bit32.ROL(x, 4))
23456789abcdef01

The changes were these, in luaconf.h:

< #define LUA_NUMBER_DOUBLE
< #define LUA_NUMBER	double
---
> /* #define LUA_NUMBER_DOUBLE */
> #define LUA_NUMBER	long double
> 
> #define LUA_USELONGLONG
387,388c389,390
< #define LUA_NUMBER_SCAN		"%lf"
< #define LUA_NUMBER_FMT		"%.14g"
---
> #define LUA_NUMBER_SCAN		"%Lf"
> #define LUA_NUMBER_FMT		"%.14Lg"
391c393
< #define lua_str2number(s,p)	strtod((s), (p))
---
> #define lua_str2number(s,p)	strtold((s), (p))
425c427
< #define LUA_INTEGER	ptrdiff_t
---
> #define LUA_INTEGER	long long
431c433
< #define LUA_UNSIGNED	unsigned LUA_INT32
---
> #define LUA_UNSIGNED	unsigned long long


plus these in lbitlib.c: (I did not change the lib name to bit64 ;)

< #define NBITS	32
---
> #define NBITS	64
111c111
<   if (i < 0 || !(r & (1 << (NBITS - 1))))
---
>   if (i < 0 || !(r & ((b_uint)1 << (NBITS - 1))))

(This last one is actually a bug fix...)

Probably NBITS should be moved to luaconf.h...

-- Roberto