我想了解Go Sqrt的实现,并不能完全理解Float64bits
函数的功能。我有一些测试代码和输出如下。为什么ix的价值在这个操作中发生了如此剧烈的变化?Golang Float64bits
package main
import ("math"
"fmt")
func main() {
var x float64 = 4
fmt.Printf("The value of x is: %v \n", x)
ix := math.Float64bits(x)
fmt.Printf("The value of ix is: %v \n", ix)
fmt.Printf("The type of ix is: %T \n", ix)
}
The value of x is: 4
The value of ix is: 4616189618054758400
The type of ix is: uint64
我相信你正在看的价值是十六进制。如果你知道浮点表示的公式(更多信息在这里https://en.wikipedia.org/wiki/IEEE_floating_point),那么你理论上可以将它应用到该值,它会给你4。 – evanmcdonnal