-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1796 from nspcc-dev/compiler/pow
Add syscalls for POW and SQRT opcodes
- Loading branch information
Showing
11 changed files
with
227 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package math | ||
|
||
import "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal" | ||
|
||
// Pow returns a^b using POW VM opcode. | ||
// b must be >= 0 and <= 2^31-1. | ||
func Pow(a, b int) int { | ||
return neogointernal.Opcode2("POW", a, b).(int) | ||
} | ||
|
||
// Sqrt returns positive square root of x rounded down. | ||
func Sqrt(x int) int { | ||
return neogointernal.Opcode1("SQRT", x).(int) | ||
} | ||
|
||
// Sign returns: | ||
// | ||
// -1 if x < 0 | ||
// 0 if x == 0 | ||
// +1 if x > 0 | ||
func Sign(a int) int { | ||
return neogointernal.Opcode1("SIGN", a).(int) | ||
} | ||
|
||
// Abs returns absolute value of a. | ||
func Abs(a int) int { | ||
return neogointernal.Opcode1("ABS", a).(int) | ||
} | ||
|
||
// Max returns maximum of a, b. | ||
func Max(a, b int) int { | ||
return neogointernal.Opcode2("MAX", a, b).(int) | ||
} | ||
|
||
// Min returns minimum of a, b. | ||
func Min(a, b int) int { | ||
return neogointernal.Opcode2("MIN", a, b).(int) | ||
} | ||
|
||
// Within returns true if a <= x < b. | ||
func Within(x, a, b int) bool { | ||
return neogointernal.Opcode3("WITHIN", x, a, b).(bool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package neogointernal | ||
|
||
// Opcode1 emits opcode with 1 argument. | ||
func Opcode1(op string, arg interface{}) interface{} { | ||
return nil | ||
} | ||
|
||
// Opcode2 emits opcode with 2 arguments. | ||
func Opcode2(op string, arg1, arg2 interface{}) interface{} { | ||
return nil | ||
} | ||
|
||
// Opcode3 emits opcode with 3 arguments. | ||
func Opcode3(op string, arg1, arg2, arg3 interface{}) interface{} { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters