-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
0xFFFFFFFF convert to int32 result in 4294967295? #5251
Comments
I think that A should raise a compile error, or at least a warning. B should behave like A currently does. |
A should produce -1, that's what was asked for. B should produce a compiletime error. |
I think A is ok, it use a hex format to represent a -1 value. The type must be int32 becasue I specify it. |
We answer the question at the same time, lol. |
I don't think B should produce a compile time error. When I call @khchen I recently learned how this is possible to happen. In the compiler all integers are stored as value of BiggestInt. This value is tagged with the explicit type, in this case int32, but that does not limit it to be out of the range of an int32. Operations are still on BiggestInt range. |
Here is a similar problem: import typetraits
proc `$`*[T](some:typedesc[T]): string = name(T)
const
A = 0xFFFFFFFE'u32 #'
B = not A
echo A.type
echo B.type
echo B.int64
# echo B # Compile Error: cannot convert -4294967295 to uint64
echo cast[uint32](B) output: B is already uint32, however, I need use cast[uint32] to get the correct value. |
Another type problem: import typetraits
proc `$`*[T](some:typedesc[T]): string = name(T)
const
A = -2147483648
B = 2147483647
C = -2147483648.int
echo A.type # int64, why not just int?
echo B.type # int, correct
echo C.type # int, correct A literal should be a int type if it is possible. |
I think this bug should get a tag |
See also issue #6829. |
Now it fails to compile with "temp.nim(8, 17) Error: 4294967295 can't be converted to int32" which is good. And the other example works as expected now. |
Nim Compiler Version 0.16.0
output is the same on both 32/64 bit mode:
-1
4294967295
type of B is int32
B > int32.high ? true
The text was updated successfully, but these errors were encountered: