4 ms·
It's probably to do with the fact that one is a "number". If I'm correct, that means in `x[1.0 << s]`. 1.0 is a "number", therefore the shift is valid, but in
by cshenton 9y ago
It's probably to do with the fact that one is a "number".
If I'm correct, that means in `x[1.0 << s]`. 1.0 is a "number", therefore the shift is valid, but in `var u = 1.0 << s`, it's a float64, and therefore the shift is invalid.
see also: https://blog.golang.org/constants https://blog.golang.org/constants
- simonbyrne 9y agoAh, thanks.
- tapirl 9y ago@cshenton 's answer is not perfect. The "var u = 1.0<<s" in go spec is illegal is because s is a variable, so 1.0 will be deduced as a flaot64. However, in "x[1.0 << s]", s is a constant, so 1.0 will be deduced as int.