neoneo-go/pkg/interop/math/math.go
Roman Khimov b56e028733 *: add more package-specific documentation
For the most important packages at least.
2021-03-19 16:18:45 +03:00

46 lines
1 KiB
Go

/*
Package math provides access to useful numeric functions available in Neo VM.
*/
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)
}