[fpc-devel] Different results of random(int32) and random(int64) for negative limit value

Ozz Nixon ozznixon at gmail.com
Sat May 20 23:25:55 CEST 2017


Well, I waited to see if one of the designers would have answer it... you are not passing it a negative, nor is it responding with a negative. You are passing it with the high (MSR) bit on, Int32(-16) = 1000000000010000

The compiler is obviously type casting the result to Int32, showing as -9 etc.

I have noticed when working with Int64, FPC is actually working as UInt64 is some of my other projects.

My two cents.
O.

-----Original Message-----
From: fpc-devel [mailto:fpc-devel-bounces at lists.freepascal.org] On Behalf Of Bart
Sent: Saturday, May 20, 2017 5:00 PM
To: FPC developers' list <fpc-devel at lists.freepascal.org>
Subject: Re: [fpc-devel] Different results of random(int32) and random(int64) for negative limit value

On 5/20/17, Jonas Maebe <jonas at freepascal.org> wrote:

> random(x) is undefined for negative parameters. It should have had an 
> unsigned parameter, like in Turbo Pascal (where it is word). Delphi 
> defines it as always returning a positive value, but I don't know what 
> happens if you pass a negative parameter there.

I already reported that the documentation is a bit "off":
https://bugs.freepascal.org/view.php?id=31642

Bart
_______________________________________________
fpc-devel maillist  -  fpc-devel at lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel




More information about the fpc-devel mailing list