码迷,mamicode.com
首页 > 其他好文 > 详细

06_复数的使用

时间:2019-08-31 15:19:44      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:Go语言   提取   ima   func   使用   mamicode   oat   package   mic   

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\n", t) //打印t的类型
	//自动识别类型、
	var t1 = 3 + 4i
	fmt.Printf("%T\n", 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\n", b, b)//b=(2+3i),b=complex128
}

结果:

                           技术图片

 

   

06_复数的使用

标签:Go语言   提取   ima   func   使用   mamicode   oat   package   mic   

原文地址:https://www.cnblogs.com/zhaopp/p/11438897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!