Skip to content
Related Articles

Related Articles

Improve Article

complx.Pow() Function in Golang With Examples

  • Last Updated : 28 Apr, 2020

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
  • Pow(0, ±0) returns 1+0i
  • Pow(0, c) for real(c)<0 returns Inf+0i if imag(c) is zero, otherwise Inf+Inf i

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)
My Personal Notes arrow_drop_up
Recommended Articles
Page :