I have found that RoundRealToNearestInteger does not always round a value ending in 0.5 correctly. Here are some examples:
int Temp;
Temp = RoundRealToNearestInteger(2.5); // Temp = 2 Should be 3
Temp = RoundRealToNearestInteger(7.5); // Temp = 8 Correct
Temp = RoundRealToNearestInteger(8.5); // Temp = 8 Should be 9
Temp = RoundRealToNearestInteger(8.50000000001); // Temp = 9 Correct
I assume the source of the problem is that some of these values can't be exactly represented in binary and end up being one binary digit less than 0.5. This is shown by the last example where adding a small epsilon gives the correct result.
The only work around I can think of is to manully add an epsilon every time I use this funciton, like this:
Temp = RoundRealToNearestInteger(NumberToRound + 0.0000000001);
Anybody have any better ideas?
Tony G.