Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-11

function samevalue in unit math of FPC-2.2.4

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alain Michaud

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

Reply by email