ADVERTISEMENT
ADVERTISEMENT

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 IsInfSign int
	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

Golang math Package Constants and Functions »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.