Open In App

complx.Rect() Function in Golang With Examples

Last Updated : 28 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

complx.Rect() Function in Golang returns the complex number x with polar coordinates r, θ. It takes the float value as input and return complex number. This method belongs to complex package.

Syntax:

func Rect(r, θ float64) complex128;

Here, r and θ are the complex numbers with float64 real as well as imaginary parts.

Return Value: It returns a complex number of polar coordinates r and θ.

Example 1: This example computes the value by passing arguments(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)) 
}


Output:

(2.6+4.3i)

Example 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))
}


Output:

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads