lua-users home
lua-l archive

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


G'Day,

	I have been trying to debug a function I wrote in C for Lua.  The
function ultimately returns a number to Lua, and this is where things
went a little hairy.  Below is a list of some test values I tried and
the result received by Lua after a lua_pushnumber(L, test) call:

test =
0.0	-> 2.0861572685107e-314
1.0	-> 0.0078125018663742
1.5	-> 0.01406250335649
1.9	-> 1.200000048161
1.99	-> 1.9200003151898
1.999	-> 1.9919998650556
1.9999	-> 1.9992001061444
2.0	-> 2.0000004777918
3.0	-> 32.000007644669
4.0	-> 512.0001223147
5.0	-> 2048.0004892588

	When I changed from lua_pushnumber() to lua_pushinteger() and returned
integer values rather than floating point values I received the expected
number every time.  This seems to be some sort of an oddity with
lua_pushnumber(), though things have worked perfectly fine in other
programs where we have used this function.  However, the problem seems
to persist in this program across rewrites and recompiles.  It is too
simple a block to be wrong anyway (lua_Number test = ??;
lua_pushnumber(L, test); return 1).   There is a fairly obvious pattern
in these erroneous values, but why it is happening is beyond me.

	This is tested on Lua 5.1.1 compiled for an ARM Linux system.

-- Matthew