2021-03-19 09:11:48 +00:00
|
|
|
/*
|
|
|
|
Package math provides access to useful numeric functions available in Neo VM.
|
|
|
|
*/
|
2021-03-02 11:19:13 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Sqrt returns a positive square root of x rounded down.
|
2021-03-02 11:19:13 +00:00
|
|
|
func Sqrt(x int) int {
|
|
|
|
return neogointernal.Opcode1("SQRT", x).(int)
|
|
|
|
}
|
2021-03-02 11:56:32 +00:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Abs returns an absolute value of a.
|
2021-03-02 11:56:32 +00:00
|
|
|
func Abs(a int) int {
|
|
|
|
return neogointernal.Opcode1("ABS", a).(int)
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Max returns the maximum of a, b.
|
2021-03-02 11:56:32 +00:00
|
|
|
func Max(a, b int) int {
|
|
|
|
return neogointernal.Opcode2("MAX", a, b).(int)
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Min returns the minimum of a, b.
|
2021-03-02 11:56:32 +00:00
|
|
|
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)
|
|
|
|
}
|