[fpc-devel] function samevalue in unit math of FPC-2.2.4

Alain Michaud Alain.Michaud at nrc-cnrc.gc.ca
Thu Nov 12 19:36:11 CET 2009


Hi,

   the function math.samevalue does not seem to work for small numbers:

See FPC-2.2.4  unit math lines 2177, 2155, 2195:



    function SameValue(const A, B: Double; Epsilon: Double): Boolean;
    begin
     if (Epsilon=0) then
       Epsilon:=Max(Min(Abs(A),Abs(B))*DZeroResolution,DZeroResolution);
     if (A>B) then
       Result:=((A-B)<=Epsilon)
     else
       Result:=((B-A)<=Epsilon);
   end;



For example 1e-40 and 2e-40 will return TRUE!

One possible fix would be:

 >>>>  Epsilon:=Max(Abs(A),Abs(B))*DZeroResolution;

Also the constants DZeroResolution and EZeroResolution seem to be larger 
than necessary.

Thank you

Alain




More information about the fpc-devel mailing list