go IsInf()
IsInf()方法语法
func IsInf(f float64, sign int) bool
go源码对IsInf()方法的介绍:
IsInf reports whether f is an infinity, according to sign. If sign > 0, IsInf reports whether f is positive infinity. If sign < 0, IsInf reports whether f is negative infinity. If sign == 0, IsInf reports whether f is either infinity.
即,golang的math.IsInf()方法可以用于判断f是否为无穷大的值,如果sign大于0,则当f为正无穷大时,返回true;当sign小于0时,f为负无穷大,则返回true;当sign等于0,不管f是正还是负,只要是无穷大,都可以返回true。
math.ISInf()方法实例代码
func main() {
t1 := math.IsInf(math.Inf(1), 2)
fmt.Println(t1)
t2 := math.IsInf(math.Inf(-1), -2)
fmt.Println(t2)
t3 := math.IsInf(math.Inf(1), 0)
fmt.Println(t3)
}
运行go文件,得到输出:
true
true
true