MCPcopy Index your code
hub / github.com/chain/Core / opMod

Function opMod

protocol/vm/numeric.go:210–239  ·  view source on GitHub ↗
(vm *virtualMachine)

Source from the content-addressed store, hash-verified

208}
209
210func 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
241func opLshift(vm *virtualMachine) error {
242 err := vm.applyCost(8)

Callers

nothing calls this directly

Calls 3

applyCostMethod · 0.80
popInt64Method · 0.80
pushInt64Method · 0.80

Tested by

no test coverage detected