Golang complx.IsInf()的应用及实例
complx.IsInf()函数 在Golang中,此函数用于判断复数x的实部或虚部是否为无穷大值,其返回值为布尔类型。
语法:
func IsInf(x complex128) bool
其中,x为所有实部和虚部均为float64类型的复数。
返回值:
该函数返回一个布尔值,为true或false。
例1:
// Golang程序示例
// 使用complx.IsInf()函数
package main
// 导入fmt和math/cmplx库
import (
"fmt"
"math/cmplx"
)
// 调用主函数
func main() {
// 创建一个复数1 + 5i
infy := complex(1, 5)
// 检查它是否为无穷大值
fmt.Printf("%t", cmplx.IsInf(infy))
}
输出:
false
例2:
// Golang程序示例
// 使用complx.IsInf()函数
package main
// 导入fmt、math和math/cmplx库
import (
"fmt"
"math"
"math/cmplx"
)
// 调用主函数
func main() {
// 创建无穷大变量
inf := math.Inf(1)
// 创建无穷大的复数即(无穷大 + 无穷大i)
infy := complex(inf, inf)
// 检查它是否为无穷大值
fmt.Printf("%t", cmplx.IsInf(infy))
}
输出:
true
极客教程