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


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

complx.Rect() Golang中的函數返回具有極坐標r,θ的複數x。它以float值作為輸入並返回複數。此方法屬於複雜包。

用法:

func Rect(r, θ float64) complex128;

在此,r和θ是具有float64實部和虛部的複數。

返回值:它返回複數個極坐標r和θ。

範例1:本示例通過傳遞參數(5,45)來計算值。



// Golang program to illustrate 
// the complx.Rect() Function 
  
 package main  
   
// importing fmt and math/cmplx 
  import ( 
      "fmt" 
      "math/cmplx" 
)  
   
    // Calling Main method 
    func main () { 
   
    // using the function 
    fmt.Printf ("%.1f", cmplx.Rect (5, 45))  
}

輸出:

(2.6+4.3i)

範例2:

// Golang program to illustrate 
// the complx.Rect() Function 
  
 package main 
  
// importing fmt, math and math/cmplx 
import ( 
"fmt"
"math"
"math/cmplx"
) 
  
// Calling Main method 
func main() { 
  
    // using the function    
    fmt.Printf("%.1f,", cmplx.Rect(5, 4*math.Pi))  
    fmt.Printf("%.1f", cmplx.Rect(5, 90)) 
}

輸出:

(5.0-0.0i),(-2.2+4.5i)

相關用法


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