Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/Math Unit    [ Add a report in this area ]  
Report #:  91135   Status: Closed
TotalVariance() function Extended version returns wrong value.
Project:  Delphi Build #:  15.0.3953.35171
Version:    15.1 Submitted By:   Hideaki Tominaga
Report Type:  Basic functionality failure Date Reported:  1/26/2011 9:23:18 PM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   281709
Resolution: Duplicate (Resolution Comments) Resolved in Build: : 16.0.4052.36677
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 30
Description
TotalVariance() function Extended version returns wrong value.

Added by Sysop
<<<<<<
This issue is similar to QC#91107.
>>>>>>
Steps to Reproduce:
procedure TForm1.Button1Click(Sender: TObject);
var
  TempS : array of Single;
  TempD : array of Double;
  TempE : array of Extended;
  vValueS: Single;
  vValueD: Double;
  vValueE: Extended;
begin
  // Single
  SetLength(TempS, 3);
  TempS[0]  := 1;
  TempS[1]  := 3;
  TempS[2]  := 8;
  vValueS := Math.TotalVariance(TempS);

  // Double
  SetLength(TempD, 3);
  TempD[0]  := 1;
  TempD[1]  := 3;
  TempD[2]  := 8;
  vValueD := Math.TotalVariance(TempD);

  // Extended
  SetLength(TempE, 3);
  TempE[0]  := 1;
  TempE[1]  := 3;
  TempE[2]  := 8;
  vValueE := Math.TotalVariance(TempE);

  ShowMessage(FloatToStr(vValueS) + #$0D#$0A +
              FloatToStr(vValueD) + #$0D#$0A +
              FloatToStr(vValueE) + #$0D#$0A);
end;


EXP:
--------------------
Single: 26
Double: 26
Extended: 26

ACT:
--------------------
Single: 26 (OK)
Double: 26 (OK)
Extended: -70 (NG)
Workarounds
None
Attachment
None
Comments

Tomohiro Takahashi at 1/27/2011 6:20:21 AM -
This issue is similar to QC#91107. So, please try to use your own function as below.
------------------
{$O-}
function MyTotalVariance(const Data: array of Extended): Extended;
var
  Sum, SumSquares: Extended;
begin
  SumsAndSquares(Data, Sum, SumSquares);
  Result := SumSquares - Sqr(Sum)/(High(Data) - Low(Data) + 1);
end;
{$O+}

...
...
  vValueE := MyTotalVariance(TempE);
...
------------------

Eric Thorniley at 2/11/2011 5:25:45 PM -
See also QC91518

Server Response from: ETNACODE01