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:
// Golang program to illustrate // the complx.Polar() Function package main // importing fmt, math and math/cmplx import ( "fmt" "math" "math/cmplx" ) // Calling Main func main() { // getting the r and theta value r, theta := cmplx.Polar(7i) // calculate the value in Pi format. p := theta/math.Pi // printing the values r and p. fmt.Printf( "rValue: %.1f, pValue: %.1f*Pi" , r, p) } |
Output:
rValue: 7.0, pValue: 0.5*Pi
Example 2:
// Golang program to illustrate // the complx.Polar() Function package main // importing fmt, math and math/cmplx import ( "fmt" "math" "math/cmplx" ) // Calling Main func main() { // We can create a complex number like this also. n := complex(5, 6) // getting the r and theta value of complex number 5 + 6i r, theta := cmplx.Polar(n) // calculate the value in Pi format. p := theta/math.Pi // printing the values r and p. fmt.Printf( "rValue: %.1f, pValue: %.1f*Pi" , r, p) } |
Output:
rValue: 7.8, pValue: 0.3*Pi