Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi    [ Add a report in this area ]  
Report #:  134748   Status: Resolved
Floating point comparison error
Project:  Delphi Build #:  Delphi XE6 6.3
Version:    20.0 Submitted By:   Trevor Magnusson
Report Type:  Basic functionality failure Date Reported:  11/9/2015 6:29:08 PM
Severity:    Critical / Show Stopper Last Updated: 11/10/2015 9:58:20 AM
Platform:    32 Bit Internal Tracking #:   71727
Resolution: Cannot Reproduce (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
Floating point comparison code fails, a value of 1.0 is reported as being <= 0.0.
Steps to Reproduce:
***********
Conditions:
***********
(a) array must be non-zero-based
(b) array must be of type double or single (integer & extended work fine)
(c) array indeces must be expressions, not simple constants
(d) range checking {$R+} must be switced on at time of comparison
(e) the raise exception code must be simple, and not include certain arithmetic/conversion calls (hence error string loaded in advance)
(f) compiler optimisation must be switched ON (g) target must be Win32

************
Sample Code:
************
program tmXE6BugC;

{$APPTYPE CONSOLE}
uses
  sysutils;

// {$R *.RES}

procedure TestError;
var
  Count  : integer;
  Values : array [1..2] of double;
  ErrMsg : string;

begin
  Count := 2;
  Values [1] := 0;
  Values [2] := 1;

  ErrMsg :=
    'Non-increasing values:'                        +#13+#10+
    'Count='+inttostr(Count)                        +#13+#10+
    'Values [Count]='  +FloatToStr(Values [Count])  +#13+#10+
    'Values [Count-1]='+FloatToStr(Values [Count-1])+#13+#10+
    'Compiler believes: '+
    FloatToStr(Values [Count]) + '<=' +FloatToStr(Values [Count-1]);

  {$R+}
  if Values [Count] <= Values [Count-1] then begin
    raise exception.create (ErrMsg);
  end;
  {$R-}
end;

begin
  TestError;
end.
Workarounds
If any of the listed conditions above is broken, the bug does not occur.
Attachment
None
Comments

Trevor Magnusson at 11/10/2015 5:05:58 PM -
If the steps listed are followed, the bug is rock solid, 100% repeatable, on multiple operating systems. I suspect I spent considerably more time researching and identifying it that the person who declared it resolved.

Server Response from: ETNACODE01