In ISO mode, round(x) function does not round up x when the integral part of x is even and its fractional part is = 0.5
Original Reporter info from Mantis: juancdiaz
-
Reporter name: Juan Díaz
Original Reporter info from Mantis: juancdiaz
- Reporter name: Juan Díaz
Description:
When compiling in ISO mode, either from the command line (-Miso) or with the {$MODE ISO} switch in the source code file, the round(x) function does not round up x when the integral part of x is even and its fractional part is = 0.5.
For instance, round(12.5) yields 12 and round(-4-5) yields -4, while the ISO 7185:1990 standard requires the round(x) function to be equivalent to trunc(x+0.5) if x is positive or zero; otherwise it shall be equivalent to trunc(x-0.5). That is to say, for the examples given above round(12.5) should produce 13 and round(-4.5) should produce -5.
In the FPC documentation one can read FPC uses the banker's rounding algorithm, but it would be great if in cases like the ones described above FPC's round function behaved in compliance with the ISO 7185 standard. I am hopeful that this issue will be fixed soon.
Steps to reproduce:
Just write a simple test program where round is called with a positive real number whose integral part is even and its fractional part is = 0.5, and then with a negative real number with the same characteristics. Example:
program TestRoundFunction(output);
begin
writeln('round(12.5) = ', round(12.5));
writeln('round(-4.5) = ', round(-4.5))
end.
Compile from the command line with -Miso or add the {$MODE ISO} switch before the begin keyword and compile from within the IDE.
Mantis conversion info:
- Mantis ID: 35626
- OS: Windows 7
- Fixed in version: 3.3.1
- Fixed in revision: 43281 (#d3c898a9)
- Monitored by: » @KaiBurghardt (Kai Burghardt)