# Golang math.IsInf() Function with Examples

Golang | math.IsInf() Function: Here, we are going to learn about the IsInf() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 01, 2021

## math.IsInf()

The IsInf() function is an inbuilt function of the math package which is used to check whether the given parameter (f) is an infinity, according to another given parameter (sign). If sign > 0, IsInf() checks whether f is positive infinity. If sign < 0, IsInf() checks whether f is negative infinity. If sign == 0, IsInf() checks whether f is either infinity.

It accepts two parameters (f, sign), and checks whether f is an infinity, according to sign.

Syntax:

```func IsInf(f float64, sign int) bool
```

Parameter(s):

• f : The value to be used to check the positive or negative infinity.
• sign : An integer value to be compared with f.

Return Value:

The return type of IsInf() function is a bool, it checks whether f is an infinity, according to sign.

Example 1:

```// Golang program to demonstrate the
// example of math.IsInf() Function

package main

import (
"fmt"
"math"
)

func main() {
fmt.Println(math.IsInf(math.Inf(1), 1))
fmt.Println(math.IsInf(math.Inf(1), -1))
fmt.Println(math.IsInf(math.Inf(1), 0))

fmt.Println(math.IsInf(math.Inf(-1), 1))
fmt.Println(math.IsInf(math.Inf(-1), -1))
fmt.Println(math.IsInf(math.Inf(-1), 0))
}
```

Output:

```true
false
true
false
true
true
```

Example 2:

```// Golang program to demonstrate the
// example of math.IsInf() Function

package main

import (
"fmt"
"math"
)

func main() {
var IsInfX float64
var result bool

IsInfX = math.Inf(1)
IsInfSign = 1
result = math.IsInf(IsInfX, IsInfSign)
fmt.Println("IsInf(", IsInfX, ",", IsInfSign, ") = ", result)

IsInfX = math.Inf(1)
IsInfSign = -1
result = math.IsInf(IsInfX, IsInfSign)
fmt.Println("IsInf(", IsInfX, ",", IsInfSign, ") = ", result)

IsInfX = math.Inf(1)
IsInfSign = 0
result = math.IsInf(IsInfX, IsInfSign)
fmt.Println("IsInf(", IsInfX, ",", IsInfSign, ") = ", result)

IsInfX = math.Inf(-1)
IsInfSign = 1
result = math.IsInf(IsInfX, IsInfSign)
fmt.Println("IsInf(", IsInfX, ",", IsInfSign, ") = ", result)

IsInfX = math.Inf(-1)
IsInfSign = -1
result = math.IsInf(IsInfX, IsInfSign)
fmt.Println("IsInf(", IsInfX, ",", IsInfSign, ") = ", result)

IsInfX = math.Inf(-1)
IsInfSign = 0
result = math.IsInf(IsInfX, IsInfSign)
fmt.Println("IsInf(", IsInfX, ",", IsInfSign, ") = ", result)
}
```

Output:

```IsInf( +Inf , 1 ) =  true
IsInf( +Inf , -1 ) =  false
IsInf( +Inf , 0 ) =  true
IsInf( -Inf , 1 ) =  false
IsInf( -Inf , -1 ) =  true
IsInf( -Inf , 0 ) =  true
```