Standard library / go/constant
go/constant.Compare()
Compare compatible constants using a comparison token; Unknown yields false. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Compare(x_ Value, op token.Token, y_ Value) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x_ | Value | Left constant operand. |
| op | token.Token | Operator token appropriate for this operation. |
| y_ | Value | Right constant operand. |
Return Value
bool
Compare compatible constants using a comparison token; Unknown yields false.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/constant" "go/token")
func main() { fmt.Println(constant.Compare(constant.MakeInt64(42), token.GTR, constant.MakeInt64(5))) }