Golang complx.NaN() 函数与示例
complx.NaN()函数 在 Golang 中用于返回一个复数的 “非数字” 值。
语法:
func NaN() complex128
它会返回复数NaN值。让我们通过给定的示例来讨论这个概念:
示例1:
// Golang程序演示
// complx.NaN()函数
package main
import (
"fmt"
"math/cmplx"
)
// 主函数
func main() {
// 使用函数
fmt.Printf("%.1f", cmplx.NaN())
}
输出:
(NaN+NaNi)
示例2:
// Golang程序演示
// complx.NaN()函数
package main
import (
"fmt"
"math/cmplx"
)
// 主函数
func main() {
// 检查生成的值是否为非数字?
fmt.Printf("%t", cmplx.IsNaN(cmplx.NaN()))
}
输出:
true
极客教程