Re: FastCode RoundToEx
- From: "Dennis" <marianndkc@xxxxxxxxxxxxxxx>
- Date: Sat, 29 Dec 2007 16:32:29 +0100
Hi
The bug fixed RoundToEX_JFH_Pas_1
passes validation in the B&V meaning that it agrees with the ref function at
all testsets within the limit used.
The limit is
EXTENDEDLIMIT : Extended = 1.0842021725e-19;
and used like this in an absolute validation
Result := True;
Digits := 0;
X := 1.2E1;
Y := RoundToEXFunction(X, Digits);
if (Abs(Y - 1.2E1) / Y) > EXTENDEDLIMIT then
begin
ErrorTrap(ValidateNo, Digits, X);
Result := False;
Exit;
end;
and like this in a validation against the ref function
Result := True;
Digits := 0;
X := 2160134979.3;
Y1 := RoundToEX_Ref(X, Digits);
Y2 := RoundToEXFunction(X, Digits);
if Abs((Y1 - Y2) / Y1) > EXTENDEDLIMIT then
begin
ErrorTrap(ValidateNo, Digits, X);
Result := False;
end;
Best regards
Dennis Kjaer Christensen
"Dennis" <marianndkc@xxxxxxxxxxxxxxx> wrote in message
news:47766706$1@xxxxxxxxxxxxxxxxxxxxxxxxx
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
.
- References:
- FastCode RoundToEx
- From: Dennis
- Re: 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
|