[fpc-devel] Round function issue

Ewald ewald at yellowcouch.org
Sat May 25 14:54:40 CEST 2019

On 05/23/2019 09:28 PM, Juan Carlos Díaz Vigo wrote:
> I am writing to you concerning an issue that I consider as being of the
> greatest importance since it affects two compiler modes of the Free
> Pascal Compiler. The round function in FPC (version 3.0.4) when the
> parameter is equidistant from the two nearest integers (.5) rounds the
> number towards the even number. This feature of the FPC's round transfer
> function when it comes to rounding (.5) integers hinders both compliance
> with the ISO 7185 standard and compatibility with Turbo Pascal.
What you are seeing is the so-called bankers rounding, where a halfway
fraction is indeed rounded toward the even number.

I was going to answer: "Use SetRoundingMode", but then I remembered that
there was a thread on this list about rounding modes quite some time ago
(2013), it was called "math round vs banker's round".

One of the replies of that thread, given By Sevn Barth was:
"Just checked again, most FPUs only seem to support "banker's rounding",
"round up", "round down" and "truncate", so these four are the only ones
supported by FPC's and Delphi's rounding mechanism. So if you want
normal mathematical rounding then you'll need to write your own function."

Since you state that there is an ISO standard that demands regular
rounding (not bankers rounding), and FPC has an ISO mode, I would
suggest you file a bug on this for the ISO-compliant mode.


More information about the fpc-devel mailing list