diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-20 11:12:59 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-20 11:12:59 -0300 |
commit | 8a0acf0898fc9bd990fc10275e72c89a6ca829a6 (patch) | |
tree | a73858766bcefd6a96f63ffc70f16c318dee1853 /lvm.c | |
parent | e2be310a85df0b8eb5c406aa0397088a66b98c47 (diff) | |
download | lua-8a0acf0898fc9bd990fc10275e72c89a6ca829a6.tar.gz lua-8a0acf0898fc9bd990fc10275e72c89a6ca829a6.tar.bz2 lua-8a0acf0898fc9bd990fc10275e72c89a6ca829a6.zip |
comments
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.210 2014/05/14 19:47:11 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.211 2014/05/15 20:08:32 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 | */ |
@@ -452,7 +452,8 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
452 | 452 | ||
453 | 453 | ||
454 | /* | 454 | /* |
455 | ** Integer division; return 'm // n'. | 455 | ** Integer division; return 'm // n'. (Assume that C division with |
456 | ** negative operands follows C99 behavior.) | ||
456 | */ | 457 | */ |
457 | lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { | 458 | lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { |
458 | if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ | 459 | if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ |
@@ -471,7 +472,8 @@ lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { | |||
471 | 472 | ||
472 | 473 | ||
473 | /* | 474 | /* |
474 | ** Integer modulus; return 'm % n'. | 475 | ** Integer modulus; return 'm % n'. (Assume that C '%' with |
476 | ** negative operands follows C99 behavior.) | ||
475 | */ | 477 | */ |
476 | lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { | 478 | lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { |
477 | if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ | 479 | if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ |
@@ -481,7 +483,7 @@ lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { | |||
481 | } | 483 | } |
482 | else { | 484 | else { |
483 | lua_Integer r = m % n; | 485 | lua_Integer r = m % n; |
484 | if (r == 0 || (m ^ n) >= 0) | 486 | if (r == 0 || (m ^ n) >= 0) /* no rest or same signal? */ |
485 | return r; | 487 | return r; |
486 | else | 488 | else |
487 | return r + n; /* correct 'mod' for negative case */ | 489 | return r + n; /* correct 'mod' for negative case */ |