Standard library / go/constant
go/constant.BinaryOp()
Apply a compatible binary operator. QUO can yield a fraction; QUO_ASSIGN forces integer division. Use Compare or Shift separately. Zero divisors panic. Expected stdout: '7/2 3\n'.
Formal Syntax & Structure
go syntaxgo
func BinaryOp(x_ Value, op token.Token, y_ Value) ValueParameters & 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
Value
Apply a compatible binary operator.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/constant" "go/token")
func main() { x := constant.MakeInt64(7) y := constant.MakeInt64(2) fmt.Println(constant.BinaryOp(x, token.QUO, y).ExactString(), constant.BinaryOp(x, token.QUO_ASSIGN, y))}