Golang complx.NaN() 函数与示例

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程