[fpc-pascal] subtract longwords with rollover

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Thu Nov 28 18:18:11 CET 2013


Klaus Hartnegg wrote:
> Hi,
> 
> How can I subtract two longwords such that when the result becomes 
> negative, it rolls over?
> 
> A := A - B triggers runtime error 201 when the result is negative.
> 
> dec (A,B) rolls over, but triggers runtime error 201 when A is higher 
> than the highest possible value of longint.
> 
> Is dec only declared for longint, but not for longword?
> 
> dec(longint(A),B) fails when the result is larger than 2 billion.
> 
> I cannot use longint instead of longword, this causes problems in other 
> parts of the code.

What happens if you explicitly disable checking using $Q- $R-

Remember that converting $80000000 to base10 might be dismal.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list