Re: [fpc-devel] wrong result for abs(low(int64))

2024-04-04 Thread Bart via fpc-devel
On Thu, Apr 4, 2024 at 9:49 PM Martin Frb via fpc-devel wrote: > The below writes: -9223372036854775808 > > Shouldn't absolute return a positive number? > > program Project1; > begin >writeln( abs(low(int64)) ); > end. See https://gitlab.com/freepascal.org/fpc/source/-/issues/40694 There

Re: [fpc-devel] wrong result for abs(low(int64))

2024-04-04 Thread J. Gareth Moreton via fpc-devel
Essentially, an arithmetic overflow is happening.  Since the largest Int64 possible is 9,223,372,036,853,775,807, going one above that (the result to abs(low(int64))) wraps back around to -9,223,372,036,853,775,808. Internally, you can think about negating (positing?) a negative number as

Re: [fpc-devel] wrong result for abs(low(int64))

2024-04-04 Thread Martin Frb via fpc-devel
On 04/04/2024 16:39, J. Gareth Moreton via fpc-devel wrote: Essentially, an arithmetic overflow is happening.  Since the largest Int64 possible is 9,223,372,036,853,775,807, going one above that (the result to abs(low(int64))) wraps back around to -9,223,372,036,853,775,808. Internally, you

[fpc-devel] wrong result for abs(low(int64))

2024-04-04 Thread Martin Frb via fpc-devel
The below writes:  -9223372036854775808 Shouldn't absolute return a positive number? program Project1; begin   writeln( abs(low(int64)) ); end. Seems writeln( abs(low(longint)) ); also returns negative... ___ fpc-devel maillist -

Re: [fpc-devel] wrong result for abs(low(int64))

2024-04-04 Thread Kai Burghardt via fpc-devel
Ahoy, hoy, On 2024‑04‑04 15:14:38 +0200, Martin Frb via fpc-devel wrote: > The below writes:  -9223372036854775808 > > Shouldn't absolute return a positive number? No, see https://wiki.freepascal.org/Integer#characteristics -- Sincerely yours, Kai Burghardt signature.asc Description: PGP