Complex numbers are usually used for scientific applications and calculations. Go implements complex numbers as the primitive type. The specific operations on complex numbers are part of the math/cmplx package.
Operating complex numbers
How to do it...
- Open the console and create the folder chapter03/recipe09.
- Navigate to the directory.
- Create the complex.go file with the following content:
package main
import (
"fmt"
"math/cmplx"
)
func main() {
// complex numbers are
// defined as real and imaginary
// part defined by float64
a := complex(2, 3)
fmt.Printf("Real part: %f \n", real(a))
fmt.Printf...