complx.Rect() Function in Golang With Examples
Last Updated :
28 Apr, 2020
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).
package main
import (
"fmt"
"math/cmplx"
)
func main () {
fmt.Printf ( "%.1f" , cmplx.Rect (5, 45))
}
|
Output:
(2.6+4.3i)
Example 2:
package main
import (
"fmt"
"math"
"math/cmplx"
)
func main() {
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
Share your thoughts in the comments
Please Login to comment...