complx.Rect() Function in Golang With Examples
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)