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) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| op | token.Token | Operator token appropriate for this operation. |
| y | Value | Constant operand. |
| prec | uint | Bit 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)) }