Open In App

complx.IsInf() Function in Golang With Examples

Last Updated : 28 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

complx.IsInf() Function in Golang reports whether either real(x) or imag(x) is an infinity. The returned value is boolean.

Syntax:

func IsInf(x complex128) bool

Here, x is the set of all complex numbers with float64 real as well as imaginary parts.

Return Value: This returns a boolean value, either true or false.

Example 1: This example checks whether 1+5i is infinity or not.




// Golang program to illustrate
// the complx.IsInf() Function
  
package main
  
// importing fmt and math/cmplx
import (
    "fmt"
    "math/cmplx"
)
  
// Calling Main()
func main() {
  
        // creating a complex number 1 + 5i
    infy := complex(1, 5)  
      
    // checking if it is infinity or not?  
    fmt.Printf("%t", cmplx.IsInf(infy)) 
}


Output:

false

Example 2: This example verifies that the var infy is infinite or not.




// Golang program to illustrate
// the complx.IsInf() Function
  
package main
  
// importing fmt and math/cmplx
import (
    "fmt"
    "math"
    "math/cmplx"
)
  
// Calling Main method
func main() {
    // creating infinity variable.
    inf := math.Inf(1)
  
    // creating infinity complex
    // number i.e. (INF + INFi)
    infy := complex(inf, inf)
    // checking if it is infinity.
    fmt.Printf("%t", cmplx.IsInf(infy))
}


Output:

true


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads