Standard library / go/constant

go/constant.UnaryOp()

Apply a compatible unary operator; for complement a positive precision specifies bit width, zero means unlimited. Expected stdout: '255\n'.

Formal Syntax & Structure

go syntaxgo
func UnaryOp(op token.Token, y Value, prec uint) Value

Parameters & Attributes

NameTypeDescription
optoken.TokenOperator token appropriate for this operation.
yValueConstant operand.
precuintBit width for complement; zero means unlimited precision.

Return Value

Value

Apply a compatible unary operator; for complement a positive precision specifies bit width, zero means unlimited.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/constant"  "go/token")
func main() { fmt.Println(constant.UnaryOp(token.XOR, constant.MakeInt64(0), 8)) }
Go Reference