← All languages
Go function of the day
Random

imag

Return the imaginary part of a complex number.

Description

The imag built-in function returns the imaginary part of the complex number c. The return value will be a floating point type corresponding to the type of c: float32 for complex64, and float64 for complex128.

imag is typically used alongside real() to decompose a complex number into its component parts.

Arguments

NameDescriptionOptional
c A complex number. No

Example

c := complex(3.0, 4.0)  // 3+4i
fmt.Println(imag(c))  // 4

Reference