lua-users home
lua-l archive

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


Thanks to everyone that helped out with my yield problem earlier. I’ve reworked my app and solved that problem.

 

My next problem is related to passing float values between C++ and Lua.  I have a number in Lua (“8.2008” in particular).  If I call another Lua function with this value, it remains consistent. When I call a C function that takes a float with this value, however, it’s received as ‘8.2007999999999992”.  If I pass this value back to Lua (using lua_pushnumber), it becomes ‘8.2007999420166’.  And so on. I’m loosing precision on each Lua / C transition.

 

I’m using Lua 5.1.3 with the lnum patch (double, int64). My conversions are done via SWIG 1.3.31 wrappers.

 

Is this just a side-effect of the conversion between double and float or is there a way around this?

 

Thanks,

-Aaron