Re: FastCode RoundToEx



Hi

There is a bug in RoundTo_JFH which confused me. Now it makes more sense to
me.

Type
tRoundToRange27 = -27 .. +27;
{ Beyond above range, extended cannot represent exact multiplier.}

function RoundTo_JFH
(const aValue: Extended;
const NbrDecFractDigits: tRoundToRange27): Extended;
var LFactor: Extended; CW8087 : Word;
begin
CW8087 := Get8087CW;
if (NbrDecFractDigits < Low(tRoundToRange27)) or
(NbrDecFractDigits > High(tRoundToRange27))
then raise Exception.Create('NbrDecFractDigits out of range');
try
Set8087CW($1332);
{ i.e. extended precision and bankers rounding on a binary basis }
LFactor := IntPower(10, NbrDecFractDigits); ///<----------- LFactor
:= IntPower(10, -NbrDecFractDigits);
Result := Round(aValue*LFactor)/LFactor;
finally
Set8087CW(CW8087);
end;
end;

Best regards
Dennis Kjaer Christensen


.