package main
import (
"fmt"
"math"
)
func main() {
x, y := math.NaN(), math.MaxFloat64
fmt.Printf("%d\n", int(x))
fmt.Printf("%d\n", int(y))
}
那是我的测试代码片段。当我使用 go1.14.2 运行上面的代码时,结果是
-9223372036854775808
-9223372036854775808
但是同样的代码在go1.17.2中运行,结果是
0
9223372036854775807
我搜索了类似的问题:Why Is uint64 of NaN and MaxFloat64 equal in Golang? ,上面说在不同的硬件环境下,math.NaN() 可能不同,但是我在我的 MacOS M1 系统中运行代码,只是 golang 版本不同。为什么go1.14.2和go1.17.2结果不一样?
翻过高山走不出你
相关分类