| 208 | } |
| 209 | |
| 210 | func opMod(vm *virtualMachine) error { |
| 211 | err := vm.applyCost(8) |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | y, err := vm.popInt64(true) |
| 216 | if err != nil { |
| 217 | return err |
| 218 | } |
| 219 | x, err := vm.popInt64(true) |
| 220 | if err != nil { |
| 221 | return err |
| 222 | } |
| 223 | if y == 0 { |
| 224 | return ErrDivZero |
| 225 | } |
| 226 | |
| 227 | res, ok := checked.ModInt64(x, y) |
| 228 | if !ok { |
| 229 | return ErrRange |
| 230 | } |
| 231 | |
| 232 | // Go's modulus operator produces the wrong result for mixed-sign |
| 233 | // operands |
| 234 | if res != 0 && (x >= 0) != (y >= 0) { |
| 235 | res += y |
| 236 | } |
| 237 | |
| 238 | return vm.pushInt64(res, true) |
| 239 | } |
| 240 | |
| 241 | func opLshift(vm *virtualMachine) error { |
| 242 | err := vm.applyCost(8) |