Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Fix integer division #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lua/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ func (state *State) arith(op Op, x, y Value) Value {
// try __mod
event = metaMod

case OpQuo: // '/'
case OpQuo: // '//'
if isInteger(x) && isInteger(y) {
m, _ := toInteger(x)
n, _ := toInteger(y)
if n == 0 {
panic(fmt.Errorf("attempt to divide by zero"))
}
if n == -1 {
return m
return -m
}
q := m / n
if (m^n) < 0 && m%n != 0 {
Expand All @@ -400,7 +400,7 @@ func (state *State) arith(op Op, x, y Value) Value {
// try __idiv
event = metaIdiv

case OpDiv: // '//'
case OpDiv: // '/'
if n1, ok := toFloat(x); ok {
if n2, ok := toFloat(y); ok {
return n1 / n2
Expand Down