2

This is my test function.

if -1 != cmp(2<<32, keys[2].Distance(keys[5])) {
        t.Errorf("2<<32 should be smaller")
    }

it results in the folllowing error

constant 8589934592 overflows int

Is it possible to make this work on a 32 bit system?

edit: also this is the Distance function for comparing keys

// 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
}
5
  • 1
    are you sure the golang version you're using is 64 bit? according to the docs on 64 bit go int should be 64 bit Commented Oct 3, 2014 at 19:54
  • I just checked on a 64 bit version of go and there's no problem with 2<<32 as an int Commented Oct 3, 2014 at 19:56
  • @sourcey Run go version , what is the output on your machine. Commented Oct 3, 2014 at 19:58
  • i might be on a 32 bit actually. go -v says 'go version go1.3.1 darwin/386'. Is it possible to make this work on a 32 bit system? Commented Oct 3, 2014 at 19:59
  • @sourcey can you modify your code to use int64 explicitly? if so - you're good to go. Commented Oct 3, 2014 at 20:00

1 Answer 1

1

Make sure you work on an 64bit int, the best way is to ensure the size by using uint64

type Key int64 // or uint64

Assuming key is defined to be int, otherwise just change all your function signatures from int to int64.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.