Re: FastCode RoundToEx
- From: "Dennis" <marianndkc@xxxxxxxxxxxxxxx>
- Date: Sat, 29 Dec 2007 16:25:58 +0100
Hi
Incomplete and buggy code was given as an example. This lead to confusion.
We have to compare
function RoundToEX_Ref(const AValue: Extended; const ADigit:
TRoundToEXRangeExtended): Extended;
var
LFactor: Extended;
CW8087 : Word;
begin
CW8087 := Get8087CW;
if (ADigit < Low(TRoundToEXRangeExtended)) or (ADigit >
High(TRoundToEXRangeExtended)) then
raise Exception.Create('ADigit out of range');
try
SetPrecisionMode(pmExtended);
SetRoundMode(rmNearest);
LFactor := IntPower(10, ADigit);
Result := Round(AValue / LFactor) * LFactor;
finally
Set8087CW(CW8087);
end;
end;
and
function RoundToEX_JFH_Pas_1(const aValue: Extended; const
NbrDecFractDigits: TRoundToEXRangeExtended): Extended;
var LFactor: Extended; CW8087 : Word;
begin
CW8087 := Get8087CW;
if (NbrDecFractDigits < Low(TRoundToEXRangeExtended)) or
(NbrDecFractDigits > High(TRoundToEXRangeExtended))
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);
Result := Round(aValue*LFactor)/LFactor;
finally
Set8087CW(CW8087);
end;
end;
Best regards
Dennis Kjaer Christensen
.
- Follow-Ups:
- Re: FastCode RoundToEx
- From: Dennis
- Re: FastCode RoundToEx
- References:
- FastCode RoundToEx
- From: Dennis
- Re: FastCode RoundToEx
- From: Dennis
- FastCode RoundToEx
- Prev by Date: Re: FastCode RoundToEx
- Next by Date: Re: FastCode RoundToEx
- Previous by thread: Re: FastCode RoundToEx
- Next by thread: Re: FastCode RoundToEx
- Index(es):
Relevant Pages
|