I'm getting a strange output from the round function using fpc-3.0.4.i386-win32 on Windows XP. If I perform the following
round(I+0.5)
where I is an integer, then this happens:
I is even and positive: output is I! For example round(6.5) = 6. Result should be 7! I get the correct result if I is odd.
I is odd and negative: output is -I+1. For example round(-2.5) = -2. Result should be -3! I get the correct result if I is even.
According to my turbo Pascal book round should do the following:
"Round(x: real)
x is a real-type expression. Round returns a longint value that is the value of x rounded to the nearest whole number. If x is exactly halfway between two whole numbers, the result is the number with the greatest absolute magnitude. A runtime error occurs if the rounded value of x is not within the longint range."
Attached is a little program that tests this.
My question is, does anyone else get the same output?