1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 20:35:17 +03:00

Closes #4560: Lua uses double (again) for numbers. The float usage was not good for bit32 library where only ~24bits (out of 32) were correct, others were lost. This is supposed to be a temporary solution.

This commit is contained in:
Damjan Adamic 2017-03-06 18:21:41 +01:00
parent 6c493fddd9
commit acfeb7b47a
2 changed files with 11 additions and 11 deletions

View file

@ -153,10 +153,10 @@ static void luaPushLatLon(lua_State* L, TelemetrySensor & telemetrySensor, Telem
/* result is lua table containing members ["lat"] and ["lon"] as lua_Number (doubles) in decimal degrees */ /* result is lua table containing members ["lat"] and ["lon"] as lua_Number (doubles) in decimal degrees */
{ {
lua_createtable(L, 0, 4); lua_createtable(L, 0, 4);
lua_pushtablenumber(L, "lat", telemetryItem.gps.latitude * 0.000001f); // floating point multiplication is faster than division lua_pushtablenumber(L, "lat", telemetryItem.gps.latitude * 0.000001); // floating point multiplication is faster than division
lua_pushtablenumber(L, "pilot-lat", telemetryItem.pilotLatitude * 0.000001f); lua_pushtablenumber(L, "pilot-lat", telemetryItem.pilotLatitude * 0.000001);
lua_pushtablenumber(L, "lon", telemetryItem.gps.longitude * 0.000001f); lua_pushtablenumber(L, "lon", telemetryItem.gps.longitude * 0.000001);
lua_pushtablenumber(L, "pilot-lon", telemetryItem.pilotLongitude * 0.000001f); lua_pushtablenumber(L, "pilot-lon", telemetryItem.pilotLongitude * 0.000001);
} }
static void luaPushTelemetryDateTime(lua_State* L, TelemetrySensor & telemetrySensor, TelemetryItem & telemetryItem) static void luaPushTelemetryDateTime(lua_State* L, TelemetrySensor & telemetrySensor, TelemetryItem & telemetryItem)

View file

@ -398,8 +398,8 @@
** =================================================================== ** ===================================================================
*/ */
#define LUA_NUMBER_FLOAT #define LUA_NUMBER_DOUBLE
#define LUA_NUMBER float #define LUA_NUMBER double
/* /*
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@ -414,8 +414,8 @@
@@ lua_number2str converts a number to a string. @@ lua_number2str converts a number to a string.
@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
*/ */
#define LUA_NUMBER_SCAN "%f" #define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.7g" #define LUA_NUMBER_FMT "%.14g"
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
@ -423,7 +423,7 @@
/* /*
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations @@ l_mathop allows the addition of an 'l' or 'f' to all math operations
*/ */
#define l_mathop(x) (x##f) #define l_mathop(x) (x)
/* /*
@ -434,10 +434,10 @@
** systems, you can leave 'lua_strx2number' undefined and Lua will ** systems, you can leave 'lua_strx2number' undefined and Lua will
** provide its own implementation. ** provide its own implementation.
*/ */
#define lua_str2number(s,p) strtof((s), (p)) #define lua_str2number(s,p) strtod((s), (p))
#if defined(LUA_USE_STRTODHEX) #if defined(LUA_USE_STRTODHEX)
#define lua_strx2number(s,p) strtof((s), (p)) #define lua_strx2number(s,p) strtod((s), (p))
#endif #endif