I have to deal with large numbers in my application from time to time. So I decided to use QWord to make sure that the range will (hopefully) cover all scenarios. To make long things short, it seems that the FreePascal Compiler does all mathematical operations within the integer range. This leads to some strange behvaior, i.e. that
if QWordVariable > 8600000000 then ...
does not enter the then-section even if the QWordVariable is greater than 8600000000. Only an explicit type conversation let the if-clause working properly:
if QWordVariable > QWord(8600000000) then ...
Does someone have an idea why the compiler does not automatically convert the static number into QWord for the comparison?
Thank you very much in advance and kind regards,
LT
The highest precision unsigned type is special because Pascal has signed as base type, and does calculations in the highest common base (signed) type. Literals also default to this type.
Since that highest type is int64, it makes the range of expressions with qword and literals larger than 64-bit. (-2 ^-n .. -2^(n+1)-1 with n=63)
See also Why do Delphi and Free Pascal usually prefer a signed-integer data type to unsigned one?
I would simply use int64 till you really need that extra bit.