fix(lua): compare float with int strictly in equality (#7611)
Co-authored-by: Peter Feerick <peter.feerick@gmail.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Peter Feerick
Claude Sonnet 5
parent
db18294f78
commit
34afae5a26
Vendored
+1
-1
@@ -401,7 +401,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
|
||||
return 0; /* only numbers can be equal with different variants */
|
||||
else { /* two numbers with different variants */
|
||||
lua_Integer i1, i2; /* compare them as integers */
|
||||
return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2);
|
||||
return (tointegerexact(t1, &i1) && tointegerexact(t2, &i2) && i1 == i2);
|
||||
}
|
||||
}
|
||||
/* values have same type and same variant */
|
||||
|
||||
Vendored
+9
@@ -43,6 +43,15 @@
|
||||
#define tointeger(o,i) \
|
||||
(ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))
|
||||
|
||||
/* non-soft conversion: only integral values are converted.
|
||||
** This is the strict semantic used by equality ('==' and '~='), where a
|
||||
** non-integral float such as 0.5 must not compare equal to an integer.
|
||||
** 'tointeger' (soft, LUA_FLOORN2I) is intentionally kept for API argument
|
||||
** coercion so that EdgeTX API functions accept unrounded floats; do not
|
||||
** switch this macro back to the soft conversion. */
|
||||
#define tointegerexact(o,i) \
|
||||
(ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,0))
|
||||
|
||||
#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))
|
||||
|
||||
#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)
|
||||
|
||||
Reference in New Issue
Block a user