[fpc-devel] Round function issue
Marco van de Voort
fpc at pascalprogramming.org
Sat May 25 16:17:42 CEST 2019
Op 2019-05-25 om 14:54 schreef Ewald:
>
>> 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.
>
Moreover, his example in the bugreport rounds literals which are rounded
compiletime irrespective of setroundingmode status in the compiler program.
More information about the fpc-devel
mailing list