diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-06-09 12:53:35 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-06-09 12:53:35 -0300 |
commit | a1415c0d72053cf6f6f7e68033fa3b7f999ad960 (patch) | |
tree | b791430caba9bdbf793a5bf4f396c9796128002b | |
parent | 2ecaf181381a2fa0a5586ae246ef51ffa4067f43 (diff) | |
download | lua-5.3.1.tar.gz lua-5.3.1.tar.bz2 lua-5.3.1.zip |
bug in order NaN x int (tests must ensure that NaN does not getv5.3.1
converted to integer)
-rw-r--r-- | lvm.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.243 2015/05/22 17:48:19 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.244 2015/06/02 19:11:24 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -262,17 +262,18 @@ static int l_strcmp (const TString *ls, const TString *rs) { | |||
262 | ** is trivial. Otherwise, compare them as integers. (When 'i' has no | 262 | ** is trivial. Otherwise, compare them as integers. (When 'i' has no |
263 | ** float representation, either 'f' is "far away" from 'i' or 'f' has | 263 | ** float representation, either 'f' is "far away" from 'i' or 'f' has |
264 | ** no precision left for a fractional part; either way, how 'f' is | 264 | ** no precision left for a fractional part; either way, how 'f' is |
265 | ** truncated is irrelevant.) | 265 | ** truncated is irrelevant.) When 'f' is NaN, comparisons must result |
266 | ** in false. | ||
266 | */ | 267 | */ |
267 | static int LTintfloat (lua_Integer i, lua_Number f) { | 268 | static int LTintfloat (lua_Integer i, lua_Number f) { |
268 | #if defined(l_intfitsf) | 269 | #if defined(l_intfitsf) |
269 | if (!l_intfitsf(i)) { | 270 | if (!l_intfitsf(i)) { |
270 | if (f >= -cast_num(LUA_MININTEGER)) /* -minint == maxint + 1 */ | 271 | if (f >= -cast_num(LUA_MININTEGER)) /* -minint == maxint + 1 */ |
271 | return 1; /* f >= maxint + 1 > i */ | 272 | return 1; /* f >= maxint + 1 > i */ |
272 | else if (f <= cast_num(LUA_MININTEGER)) /* f <= minint */ | 273 | else if (f > cast_num(LUA_MININTEGER)) /* minint < f <= maxint ? */ |
273 | return 0; /* f <= minint <= i --> not(i < f) */ | ||
274 | else /* minint < f <= maxint */ | ||
275 | return (i < cast(lua_Integer, f)); /* compare them as integers */ | 274 | return (i < cast(lua_Integer, f)); /* compare them as integers */ |
275 | else /* f <= minint <= i (or 'f' is NaN) --> not(i < f) */ | ||
276 | return 0; | ||
276 | } | 277 | } |
277 | #endif | 278 | #endif |
278 | return luai_numlt(cast_num(i), f); /* compare them as floats */ | 279 | return luai_numlt(cast_num(i), f); /* compare them as floats */ |
@@ -288,10 +289,10 @@ static int LEintfloat (lua_Integer i, lua_Number f) { | |||
288 | if (!l_intfitsf(i)) { | 289 | if (!l_intfitsf(i)) { |
289 | if (f >= -cast_num(LUA_MININTEGER)) /* -minint == maxint + 1 */ | 290 | if (f >= -cast_num(LUA_MININTEGER)) /* -minint == maxint + 1 */ |
290 | return 1; /* f >= maxint + 1 > i */ | 291 | return 1; /* f >= maxint + 1 > i */ |
291 | else if (f < cast_num(LUA_MININTEGER)) /* f < minint */ | 292 | else if (f >= cast_num(LUA_MININTEGER)) /* minint <= f <= maxint ? */ |
292 | return 0; /* f < minint <= i --> not(i <= f) */ | ||
293 | else /* minint <= f <= maxint */ | ||
294 | return (i <= cast(lua_Integer, f)); /* compare them as integers */ | 293 | return (i <= cast(lua_Integer, f)); /* compare them as integers */ |
294 | else /* f < minint <= i (or 'f' is NaN) --> not(i <= f) */ | ||
295 | return 0; | ||
295 | } | 296 | } |
296 | #endif | 297 | #endif |
297 | return luai_numle(cast_num(i), f); /* compare them as floats */ | 298 | return luai_numle(cast_num(i), f); /* compare them as floats */ |
@@ -387,7 +388,7 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { | |||
387 | 388 | ||
388 | 389 | ||
389 | /* | 390 | /* |
390 | ** Main operation for equality of Lua values; return 't1 == t2'. | 391 | ** Main operation for equality of Lua values; return 't1 == t2'. |
391 | ** L == NULL means raw equality (no metamethods) | 392 | ** L == NULL means raw equality (no metamethods) |
392 | */ | 393 | */ |
393 | int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | 394 | int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { |
@@ -540,7 +541,7 @@ lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { | |||
540 | 541 | ||
541 | 542 | ||
542 | /* | 543 | /* |
543 | ** Integer modulus; return 'm % n'. (Assume that C '%' with | 544 | ** Integer modulus; return 'm % n'. (Assume that C '%' with |
544 | ** negative operands follows C99 behavior. See previous comment | 545 | ** negative operands follows C99 behavior. See previous comment |
545 | ** about luaV_div.) | 546 | ** about luaV_div.) |
546 | */ | 547 | */ |
@@ -835,7 +836,7 @@ void luaV_execute (lua_State *L) { | |||
835 | Protect(luaV_gettable(L, rb, RKC(i), ra)); | 836 | Protect(luaV_gettable(L, rb, RKC(i), ra)); |
836 | vmbreak; | 837 | vmbreak; |
837 | } | 838 | } |
838 | vmcase(OP_ADD) { | 839 | vmcase(OP_ADD) { |
839 | TValue *rb = RKB(i); | 840 | TValue *rb = RKB(i); |
840 | TValue *rc = RKC(i); | 841 | TValue *rc = RKC(i); |
841 | lua_Number nb; lua_Number nc; | 842 | lua_Number nb; lua_Number nc; |