Sign in Join

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

Mailing lists / fpc-pascal / 2017-12

Crash in Math.SameValue()

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Bart

Hi,

If you are unlucky enought to use TExtendedHelper.BuildUP() with wrong values for Mantissa and Exponent, you end up with a binary pattern that does not represent a valid floating point value.

(Yes, this is a programmer's error)

Now if you supply this "illegal" float as a parameter to Math.SameValue(), this function will crash.

Example:

uses Math;
var
  E1, E2: Extended;
  B: Boolean;
begin
  E1 := E1.BuildUp(False, 0, 16383);
  E2 := 1.0;
  B := SameValue(E2, E1); // EInvalidOp: Invalid floating point operation
end.

Is that expected (as in: documented) behaviour?
Does Delphi do the same (I cannot test myself)?

B.t.w.:

writeln(E2); // gives 'NaN';
writeln(IsNas(E2)); //gives FALSE

Bart

Reply by email