Re: FastCode RoundToEx



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




.



Relevant Pages

  • Re: Setting Requirements on Forms
    ... FrontPage uses client-side JavaScript for form validation. ... just having 16 digits doesn't make for a valid ... and in the fields collecting the credit card ...
    (microsoft.public.frontpage.programming)
  • Re: COBOL (Fujitsu v3) Data validation.
    ... my main problem is still validating that the user enters 12 digits only. ... >> I am writing a Credit Card program. ... > Let's leave validation of the input for a moment and go for your specific ... Here's a basic programming rule: ...
    (comp.lang.cobol)
  • Re: Reset Serial Number
    ... Yes I attempted to tell you exactly that in my last response. ... "Felix Wang" wrote in message ... > digits together and divides the sum by 7.If the remainder is 0, validation ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Looking for a certain regexp
    ... PG> context of credit card number validation. ... Regular expressions (especially Perl regular ... digits with appropriate modifications (add the digits of 2 digit ...
    (comp.lang.perl.misc)
  • Validation of text fields
    ... format (two digits; hyphen; three digits; hyphen; three digits). ... Error in Validation formula for "IRD Number" -- the Date Constant is ... I.e. it forces the hyphens, ...
    (microsoft.public.outlook.program_forms)