[fpc-devel] Round function

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Oct 12 15:12:08 CEST 2006


A week or two ago, I also found a problem with the Banker's Rounding
in Free Pascal. As far as I could see, with my tests I did, compared
to Delphi an know results with set values, there is a bug in FPC
implementation.

I might have forgotten to report it in Mantis though.  I will double check.

Regards,
  - Graeme -


On 12/10/06, Andrea Mauri <andrea.mauri at unimib.it> wrote:
> Using round function I implemented the RoundTo function as in Delphi:
>
> type
>   TRoundToRange = -37..37;
>
> function RoundTo(const AValue: Double; const ADigit: TRoundToRange): Double;
> var
>   LFactor: Double;
> begin
>   LFactor := IntPower(10, ADigit);
>   Result := Round(AValue / LFactor) * LFactor;
> end;
>
> In Delphi RoundTo has a known bug
> (http://qc.borland.com/wc/qcmain.aspx?d=8070).
> And in freepascal (Windows) I noticed the same behavior.
> In order to respect the banker's rounding we must obtain:
> RoundTo(1.235, -2) ->1.24
> RoundTo(1.245, -2) -> 1.24
>
> But in reality:
> RoundTo(1.235, -2) ->1.24
> RoundTo(1.245, -2) -> 1.25
>
> I didn't test it on Linux yet.
> It is a known bug?
> a.
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>


-- 
There's no place like 127.0.0.1



More information about the fpc-devel mailing list