Fixed subtraction

This commit is contained in:
Sasha Koshka 2022-11-21 13:49:36 -05:00
parent 317ad4674d
commit eea76b7e5b
1 changed files with 13 additions and 2 deletions

15
tree.go
View File

@ -259,10 +259,21 @@ func (operation *Operation) Solution () (solution int64, err error) {
solution += subSolution
}
case OpcodeSubtract:
for _, operand := range operation.operands {
if len(operation.operands) == 1 {
solution, err = operation.operands[0].Solution()
solution *= -1
if err != nil { return }
break
}
for index, operand := range operation.operands {
subSolution, err = operand.Solution()
if err != nil { return }
solution -= subSolution
if index == 0 {
solution = subSolution
} else {
solution -= subSolution
}
}
case OpcodeMultiply:
solution = 1