1
這是我的測試函數。GoLang的Int溢出
if -1 != cmp(2<<32, keys[2].Distance(keys[5])) {
t.Errorf("2<<32 should be smaller")
}
它導致folllowing錯誤
不斷8589934592溢出詮釋
是否有可能使一個32位系統上這項工作?
編輯:還這是比較關鍵
距離函數// Distance returns the distance metric in this key space
func (s *xorKeySpace) Distance(k1, k2 Key) *big.Int {
// XOR the keys
k3 := XOR(k1.Bytes, k2.Bytes)
// interpret it as an integer
dist := big.NewInt(0).SetBytes(k3)
return dist
}
你確定你使用的golang版本是64位嗎?根據文檔上的64位去int應該是64位 – 2014-10-03 19:54:02
我剛剛檢查了一個64位版本去,並沒有問題,2 << 32作爲int – 2014-10-03 19:56:35
@sourcey運行'去版本',輸出是什麼你的機器。 – nos 2014-10-03 19:58:40