Built-in function

Go complex()

Constructs a complex value from compatible floating-point components. Float32 components produce complex64; float64 components produce complex128. Untyped constants can form an untyped complex constant. Example prints 2 -3.

Formal Syntax & Structure

go syntaxgo
complex(realPart, imagPart)

Parameters & Attributes

NameTypeDescription
realPartfloating-point value or suitable constantReal component.
imagPartmatching floating-point value or suitable constantImaginary component.

Return Value

complex64, complex128 or untyped complex constant

Complex number with both components.

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  z := complex(2.0, -3.0)  fmt.Println(real(z), imag(z))}
Go Reference