當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Golang complx.Inf()用法及代碼示例

Gol語言中的complx.Inf()函數用於返回複數無窮大,complex(+ Inf,+ Inf)。要使用此函數,必須導入“math/cmplx”軟件包。

用法:

func Inf() complex128

返回類型:它返回一個複雜的無窮大。

範例1:

// Golang program to illustrate 
// the complx.Inf() Function 
  
package main 
  
// importing fmt and math/cmplx 
import ( 
    "fmt"
    "math/cmplx"
) 
  
// calling main method 
func main() { 
  
    // returns the complex Infinite number 
    fmt.Printf("%f", cmplx.Inf()) 
}

輸出:

(+Inf+Infi)

範例2:您還可以生成一個複數無窮數,如下所示

// Golang program to generate 
// complex infinite number 
  
package main 
  
// importing fmt and math 
import ( 
    "fmt"
    "math"
) 
  
// calling main method 
func main() { 
  
    // returns a infinite value 
    inf:= math.Inf(1) 
  
    // make a complex infinite number 
    cmp:= complex(inf, inf) 
  
    // print the number 
    fmt.Printf("%f", cmp) 
}

輸出:

(+Inf+Infi)

相關用法


注:本文由純淨天空篩選整理自PranchalKatiyar大神的英文原創作品 complx.Inf() Function in Golang With Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。