[fpc-devel] Numeric error in the calculation of Variance
Anton Shepelev
anton.txt at gmail.com
Sat Dec 23 13:24:11 CET 2017
Hello, all
May I ask you if there is any chance of fixing the
error in the Math unit that I reported here:
https://bugs.freepascal.org/view.php?id=32804
and provided a patch? Here is a test case:
Program Vartest;
uses Math;
const Size = 1000000;
var dataS: array of Single;
dataD: array of Double;
dataE: array of Extended;
i,n: longint;
begin
WriteLn('Each run should return a value near unity.');
WriteLn('Single:');
SetLength( dataS, Size );
for n := 1 to 4 do
begin
for i := 0 to Size - 1 do
begin
dataS[i] := 10000000 + RandG(0,1);
end;
WriteLn( Math.Variance( dataS ):5:3 );
end;
WriteLn('Double:');
SetLength( dataD, Size );
for n := 1 to 4 do
begin
for i := 0 to Size - 1 do
begin
dataD[i] := 1000000000000000 + RandG(0,1);
end;
WriteLn( Math.Variance( dataD ):5:3 );
end;
WriteLn('Extended:');
SetLength( dataE, Size );
for n := 1 to 4 do
begin
for i := 0 to Size - 1 do
begin
dataE[i] := 1000000000000000000 + RandG(0,1);
end;
WriteLn( Math.Variance( dataE ):5:3 );
end;
end.
--
Please, do not forward replies to my e-mail.
More information about the fpc-devel
mailing list