I accepted a PR for my fixed <https://github.com/robaho/fixed> project. It was 
done by an expectedly experienced developer and it includes a test case.

I find it very hard to believe that the author didn’t run and verify the test 
case, so that leaves me to believe that something in Go has changed, since the 
code won’t compile.

The offending code is in decomposer.go

        var c uint64
        for i, v := range coefficient {
                if i < 8 {
                        c |= uint64(v) << (i * 8)
                } else if v != 0 {
                        return fmt.Errorf("coefficent too large")
                }
        }

and it fails to compile with:

# github.com/robaho/fixed [github.com/robaho/fixed.test]
./decomposer.go:62:19: invalid operation: uint64(v) << (i * 8) (shift count 
type int, must be unsigned integer)

and changing the code to 

        c |= uint64(v) << (uint(i) * 8)

causes it to work. coefficient is defined as

coefficient []byte

So, the question is: why ‘i’ isn’t treated as unsigned, since it is a range 
index - won't it always be positive?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to