I found some odd looking code in the math/big library and don't understand how it works. I have extracted the constants out into an example:
package main
import (
"fmt"
"math/bits"
)
const (
_S = _W / 8 // word size in bytes
_W = bits.UintSize // word size in bits
_B = 1 << _W // digit base
_M = _B - 1 // digit mask
)
func main() {
fmt.Println(_S, _W, _B, _M)
}
Returns the error:
bug/example.go:17:13: constant 18446744073709551616 overflows int
bug/example.go:17:13: constant 18446744073709551615 overflows int
To be clear, I understand why this code doesn't work. What I'm interested in is knowing is why this error doesn't happen when this constant is used in the standard library?
I thought it might be late evaluated (ie _B - 1
) but I can see it's literally used in tests. So what value would be used here?