New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
math: MaxUint64 doesn't return correct result but an error? #38723
Comments
Show us your code. This code works fine:
The definition of |
Your code works well.
|
Is this related to untyped constant? The untyped constant math.MaxUint64 cannot infer the type from x that has no type. So it is given the default type int, so it overflows. |
Yes, the second example is due to the type inference with the untyped constant. x := math.MaxUint64 infers that Also, the first example var x uint = math.MaxUint64 still overflows on any architecture where If you want to assign |
Closing, this is working as intended. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
What did you see instead?
Notice that "1<<64" in "math.MaxUint64 = 1<<64 - 1" may cause overflow, perhas you can use "math.MaxUint64 = ^uint64(0)" instead.
The text was updated successfully, but these errors were encountered: