Skip to content
Related Articles

Related Articles

Improve Article

complx.Phase() Function in Golang with Examples

  • Last Updated : 19 Apr, 2020

In Go language, cmplx packages supply basic constants as well as mathematical functions for the complex numbers. The Phase() function in Go language is used to return the phase (also called the argument) of a given number. Moreover, this function is defined under the cmplx package. Here, you need to import “math/cmplx” package in order to use these functions.

Syntax:

func Phase(x complex128) float64

The return value is in the range [-Pi, Pi].

Example 1:




// Golang program to illustrate the complex.Phase() function
  
package main
  
import (
    "fmt"
    "math"
    "math/cmplx"
)
  
// Main function 
func main() {
  
    // using the function
    fmt.Printf("%.1f", cmplx.Phase(1i*math.Pi)+1)
}

Output:

2.6

Example 2:




// Golang program to illustrate the complex.Phase() function
  
package main
  
import (
    "fmt"
    "math"
    "math/cmplx"
)
  
// Main function
func main() {
  
    // using the function
    fmt.Printf("%.1f, ", cmplx.Phase(1i*math.Pi))
    fmt.Printf("%.1f", cmplx.Phase(2i*math.Pi)+3)
}

Output:

1.6, 4.6
My Personal Notes arrow_drop_up
Recommended Articles
Page :