OSDN Git Service

update repo
[bytom/vapor.git] / protocol / vm / numeric.go
index 0845c9c..5a388ec 100644 (file)
@@ -2,6 +2,7 @@ package vm
 
 import (
        "math"
+       "math/big"
 
        "github.com/bytom/vapor/math/checked"
 )
@@ -457,3 +458,36 @@ func opWithin(vm *virtualMachine) error {
        }
        return vm.pushBool(x >= min && x < max, true)
 }
+
+func opMulFraction(vm *virtualMachine) error {
+       if err := vm.applyCost(8); err != nil {
+               return err
+       }
+
+       z, err := vm.popInt64(true)
+       if err != nil {
+               return err
+       }
+
+       if z == 0 {
+               return ErrDivZero
+       }
+
+       y, err := vm.popInt64(true)
+       if err != nil {
+               return err
+       }
+
+       x, err := vm.popInt64(true)
+       if err != nil {
+               return err
+       }
+
+       res := big.NewInt(x)
+       res.Mul(res, big.NewInt(y)).Quo(res, big.NewInt(z))
+       if !res.IsInt64() {
+               return ErrRange
+       }
+
+       return vm.pushInt64(res.Int64(), true)
+}