Golang中如何表示无穷大
在Golang中,可以使用math
包中的Inf
函数来表示无穷大;具体来说,使用math
包中的Inf(1)
表示正无穷大,Inf(-1)
表示负无穷大。
示例如下:
package main
import (
"fmt"
"math"
)
func main() {
// 正无穷大
fmt.Println(math.Inf(1))
// 负无穷大
fmt.Println(math.Inf(-1))
}
运行结果
+Inf -Inf