File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -387,3 +387,20 @@ function test()
387387 assert (a == 1 and b == nil and c == nil )
388388end
389389test ()
390+
391+ -- issue #412
392+ -- issue #418
393+ -- Conversion from symmetric modulo is incorrect.
394+ function test ()
395+ assert (- 2 % - 2 == 0 )
396+ assert (- 1 % - 2 == - 1 )
397+ assert (0 % - 2 == 0 )
398+ assert (1 % - 2 == - 1 )
399+ assert (2 % - 2 == 0 )
400+ assert (- 2 % 2 == 0 )
401+ assert (- 1 % 2 == 1 )
402+ assert (0 % 2 == 0 )
403+ assert (1 % 2 == 1 )
404+ assert (2 % 2 == 0 )
405+ end
406+ test ()
Original file line number Diff line number Diff line change @@ -840,7 +840,7 @@ func luaModulo(lhs, rhs LNumber) LNumber {
840840 flhs := float64 (lhs )
841841 frhs := float64 (rhs )
842842 v := math .Mod (flhs , frhs )
843- if flhs < 0 || frhs < 0 && ! ( flhs < 0 && frhs < 0 ) {
843+ if frhs > 0 && v < 0 || frhs < 0 && v > 0 {
844844 v += frhs
845845 }
846846 return LNumber (v )
Original file line number Diff line number Diff line change @@ -1533,7 +1533,7 @@ func luaModulo(lhs, rhs LNumber) LNumber {
15331533 flhs := float64 (lhs )
15341534 frhs := float64 (rhs )
15351535 v := math .Mod (flhs , frhs )
1536- if flhs < 0 || frhs < 0 && ! ( flhs < 0 && frhs < 0 ) {
1536+ if frhs > 0 && v < 0 || frhs < 0 && v > 0 {
15371537 v += frhs
15381538 }
15391539 return LNumber (v )
You can’t perform that action at this time.
0 commit comments