Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Complex numbers

package main

import "fmt"

func main() {
	n := 2i + 3
	fmt.Printf("%v %T\n", n, n)
	r := real(n)
	fmt.Printf("%v %T\n", r, r)
	i := imag(n)
	fmt.Printf("%v %T\n", i, i)
	fmt.Println()

	z := 1i
	fmt.Printf("%v %T\n", z, z)
	v := z * z
	fmt.Printf("%v %T\n", v, v)
	fmt.Println(v == -1)
	fmt.Println()

	c := complex(4, 5)
	fmt.Printf("%v %T\n", c, c)
}
(3+2i) complex128
3 float64
2 float64

(0+1i) complex128
(-1+0i) complex128
true

(4+5i) complex128