Standard library / go/constant

go/constant.Real()

Extract the real part of a numeric constant. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func Real(x Value) Value

Parameters & Attributes

NameTypeDescription
xValueInput constant or Go value as specified by the function.

Return Value

Value

Extract the real part of a numeric constant.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/constant"  "go/token")
func main() {  v := constant.BinaryOp(constant.MakeInt64(2), token.ADD, constant.MakeImag(constant.MakeInt64(3)))  fmt.Println(constant.Real(v))}
Go Reference