complx.Inf() Function in Golang With Examples

complx.Inf() Function in Golang is used to returns a complex infinity, complex(+Inf, +Inf). TO use this function one must need to import the “math/cmplx” package.

Syntax:

func Inf() complex128

Return Type: It returns a complex infinity.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate
// the complx.Inf() Function
  
package main
  
// importing fmt and math/cmplx
import (
    "fmt"
    "math/cmplx"
)
  
// calling main method
func main() {
  
    // returns the complex Infinite number
    fmt.Printf("%f", cmplx.Inf())
}

chevron_right


Output:

(+Inf+Infi)

Example 2: You can also generate a complex infinite number as shown below

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to generate
// complex infinite number
  
package main
  
// importing fmt and math
import (
    "fmt"
    "math"
)
  
// calling main method
func main() {
  
    // returns a infinite value
    inf := math.Inf(1)
  
    // make a complex infinite number
    cmp := complex(inf, inf)
  
    // print the number
    fmt.Printf("%f", cmp)
}

chevron_right


Output:

(+Inf+Infi)
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.