1 shl 63 is a silent −9223372036854775808.
...Moreover, 1 shl 63 - 1
throws a compile-time error (obviously a consequence of considering it an int64
, as int64(1 shl 63) = low(int64)
):
{$mode objfpc} {$codepage utf8}
begin
writeln('“1 shl 63” is ', 1 shl 63, '.');
writeln('Type of “1 shl 63” is ', pShortString(TypeInfo(1 shl 63) + 1)^, '.');
// writeln('“1 shl 63 - 1” is ', 1 shl 63 - 1, '.'); // Error: Overflow in arithmetic operation
writeln;
writeln('“uint64(1) shl 63” is ', uint64(1) shl 63, '.'); // Workaround.
writeln('Type of “uint64(1) shl 63” is ', pShortString(TypeInfo(uint64(1) shl 63) + 1)^, '.');
end.
“1 shl 63” is -9223372036854775808.
Type of “1 shl 63” is Int64.
“uint64(1) shl 63” is 9223372036854775808.
Type of “uint64(1) shl 63” is QWord.