complx.Polar() Function in Golang With Examples
complx.Polar() Function in Golang returns the absolute value r and phase θ of x. The phase θ will be in the range [-Pi, Pi].
Syntax:
func Polar(x complex128) (r, θ float64)
Here, x is a complex number.
Return Value: The return value is in the range [-Pi, Pi].
Example 1:
package main
import (
"fmt"
"math"
"math/cmplx"
)
func main() {
r, theta := cmplx.Polar(7i)
p := theta/math.Pi
fmt.Printf( "rValue: %.1f, pValue: %.1f*Pi" , r, p)
}
|
Output:
rValue: 7.0, pValue: 0.5*Pi
Example 2:
package main
import (
"fmt"
"math"
"math/cmplx"
)
func main() {
n := complex(5, 6)
r, theta := cmplx.Polar(n)
p := theta/math.Pi
fmt.Printf( "rValue: %.1f, pValue: %.1f*Pi" , r, p)
}
|
Output:
rValue: 7.8, pValue: 0.3*Pi
Last Updated :
28 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...