我想了解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