Standard library / reflect

reflect.Value.SetComplex()

Change a settable complex64 value through its kind-specific setter. Wrong kinds or non-settable values panic; numeric conversions may narrow. Expected stdout: '(1+2i)\n'.

Formal Syntax & Structure

go syntaxgo
func (v Value) SetComplex(x complex128)

Parameters & Attributes

NameTypeDescription
xcomplex128New value; must satisfy the destination kind or assignability requirement.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { var x complex64; reflect.ValueOf(&x).Elem().SetComplex(1 + 2i); fmt.Println(x) }
Go Reference