06_复数的使用

1、go语言中有两种大小的复数 complex64和complex128,二者分别由float32和float64组成。
2、内置的complex函数,根据给定的实部和虚部创建复数,而内置的real函数和imag函数则分别提取复数的实部和虚部






package main

import "fmt"

func main() {

	var t complex128
	t = 2 + 2.1i
	fmt.Println("t值为:", t)
	fmt.Printf("the type t is %T
", t) //打印t的类型
	//自动识别类型、
	var t1 = 3 + 4i
	fmt.Printf("%T
", t1) //complex128
	//取虚部和实部
	fmt.Println("t1的实部为", real(t1), "t1的虚部为", imag(t1))

	//使用复数函数complex(),来定义复数
	//var b complex128 = complex(2, 3)
	b := complex(2, 3)
	fmt.Printf("b=%v,b=%T
", b, b)//b=(2+3i),b=complex128
}

结果:

                           

   


每天的价值就是不停息的前进!!!
原文地址:https://www.cnblogs.com/zhaopp/p/11438897.html