I turned on “Use Delphi compatible division operators”
var x : Int32 := 1/40; creates a compiler error message which is very ok telling me that “/” will return a Double which can not be assigned to a Int32; very OK.
the following code however does not work
var hwy := new array[0..125] of Double;
FOR x := hwy.GetLowerBound(0) TO hwy.GetUpperBound(0) DO BEGIN
CASE x OF
0.. 39 : hwy[x] := x/40;
40..120 : hwy[x] := 1;
END;
Console.WriteLine( 'M-Result : x='+ x.ToString('D3') + ' hwy[x]='+ hwy[x]);
END;
I toke the debugger and checked the content of the hwy array, all zeros and then all 1’s in it depending on case, but never a double i.e. 1/40 should result in 0.025; But this number is not placed into the arry of numbers.
changeing the code
0.. 39 : hwy[x] := 1/40;
fills properly the array from index [0] to [39] with 0.025
The question is: Why can the “/” operator generate a double when I enter a “1” which could also be an integer, but fails to generate a double if x is a integer. The documentation says that in division compatibility mode “/” will return always a double.
changing code again to
var y : Int32 := 1;
0.. 39 : hwy[x] := y/40;
delivers the bad results as well; It seams that one of the numbers must be a double;
But this would work without switching to the compatibility mode;
We would have to touch a lot mathematical code and do a lot testing if that can not be fixed soon.
Josef