Open In App

complx.Pow() Function in Golang With Examples

complx.Pow() Function in Golang is used to find x**y, the base-x exponential of y. For this function, one need to import the “math/cmplx” package.

Syntax:



func Pow(x, y complex128) complex128

Parameters: The parameters used are two complex numbers where complex128 is the set of all complex numbers with float64 real and imaginary parts. The return type of this function is also a complex number.

Example 1:






package main
   
import (
    "fmt"
    "math/cmplx"
)
   
func main() {
    var a complex128
    var b complex128
    a= complex(2,5)
    b= complex(3,7)
    fmt.Println(cmplx.Pow(a,b))
}

Output:

(-0.03528847161704272+0.0129436389603905i)

Example 2:




// Golang program to illustrate
// the complx.Pow() Function
  
package main
   
import (
    "fmt"
    "math/cmplx"
)
   
func main() {
    var a complex128
    var b complex128
    a= complex(1,2)
    b= complex(1,0)
      
    // using the function
    fmt.Println(cmplx.Pow(a,b))
}

Output:

(1.0000000000000002+2i)

Article Tags :