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
| Name | Type | Description |
|---|---|---|
| realPart | floating-point value or suitable constant | Real component. |
| imagPart | matching floating-point value or suitable constant | Imaginary 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))}