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