October 2015
Beginner to intermediate
400 pages
14h 44m
English
Go provides two sizes of complex numbers, complex64 and
complex128, whose components are float32 and float64
respectively.
The built-in function complex creates a complex number from its
real and imaginary components, and the built-in real and imag functions
extract those components:
var x complex128 = complex(1, 2) // 1+2i var y complex128 = complex(3, 4) // 3+4i fmt.Println(x*y) // "(-5+10i)" fmt.Println(real(x*y)) // "-5" fmt.Println(imag(x*y)) // "10"
If a floating-point literal or decimal integer literal is immediately
followed by i, such as 3.141592i or 2i,
it becomes an imaginary literal, denoting a complex
number with a zero real component:
fmt.Println(1i ...
Read now
Unlock full access