On 25 Oct 2010 at 11:21, Jonas Maebe wrote:
On 25 Oct 2010, at 11:10, Jonas Maebe wrote:
On 25 Oct 2010, at 10:43, Rugxulo wrote:
In all seriousness, I would doubt the FPC answer would ever be considered correct in this context (heh, 9 gazillion from "-2 shr 1"? highly unlikely). I'm sure they'll be glad for a test case / bug report.
Yes, that's definitely a compiler bug. Kylix also returns the same results as GPC.
Actually, it's rather strange: "shr" is a logical shift right (both in FPC and Borland Pascal, and I assume also in GPC) as opposed to an arithmetic shift right. So I guess that Kylix and GPC also perform a 64 bit logical shift right on the value, but then unlike FPC truncate the result back to 32 bits. Otherwise I'm not sure where the "-1" comes from when doing "(-2)shr 1".
I don't much understand what all this is about, but for what it's worth, here are my results with Delphi (3, 4, and 7) and BP 7.0.
program unary; begin writeln( -1 ); { -1 } writeln( 2 shr 1 ); { 1 } writeln((-2)shr 1 ); { -1; BP7=2147483647 } writeln(-(2 shr 1)); { -1 } writeln( -2 shr 1 ); { -1; BP7=2147483647 } writeln( -2 div 2 ); { -1 } end.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/