As you know, float point has a precision problem, that is a value 1 will be 0.9999999. And lua use == in C to check whether two double numbers equal. So the problem is:
a = 5.6
b = 14 * 0.4
print(a==b) ; => false
But the worse thing is:
a = 1
...
if a < 1 then print("<1") end ; => sometimes a < 1
So how can i avoid this ? I check out lua source code, it seems i can modify luai_numeq/luai_numle) macros in luaconf.h, but is this necessary ?
update
The second example is not really correct. Actually my problem is, I pass a value 1 to c/c++ which use lua_tonumber to get the value, and i store this value in a double variable, and after sometime, I push the value (lua_pushnumber) to lua, and a < 1 happened:
in lua:
my_cfunction(1)
...
in c:
int my_cfunction(lua_State *L) {
double val = lua_tonumber(L, 1);
...
...
lua_pushnumber(L, val);
in lua:
local a = my_cfunction2()
if a < 1 then ... end