Hello. I am a new student at Nim. I find that, with the following example, it produces an overflow error on the first statement, but on the second statement it gets it right. I don't understand
Thank you. Best regards. Antonio F.S.
let uint64Lit: uint64 = 18446744073709551615
echo uint64Lit
let uint64LitBis = 18446744073709551615'u64
echo uint64LitBis
Thank you for your response.
In the following examples, only uint32 and uint4 produce the overflow error. Why?
Best regards. Antonio F.S.
let uintLit: uint = 42; let uintLitBis = 42'u
let uint8Lit: uint8 = 255; let uint8LitBis = 255'u8
let uint16Lit: uint16 = 65535; let uint16LitBis = 65535'u16
let uint32Lit: uint32 = 4294967295; let uint32LitBis = 4294967295'u32
let uint64Lit: uint64 = 18446744073709551615; let uint64LitBis = 18446744073709551615'u64
literals larger than int32 automatically promoted to int64, otherwise they use type int (32-bit or 64-bit depending on the platform).
int64 literals can't be converted to uint64 type. So a workaround is to specify the type of literal with 'u64 so conversion is not needed.
Related:
Hello.
Perfectly understood.
Thank you very much.
Best regards.
Antonio F.S.