Delphi compatibility divison operators not working for

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

Thanks, logged as bugs://67777: Delphi compatibility divison operators not working for

Fixed for the next build thanks!

Any Idea when that will be fixed?

We just had a 2 hour debug session to find the following not working code as shown below

  (* Hilfsgrösse auf Basis Aktiver für Barwert anwart. IV-Rente *)
  IF ((gru.erg[3] = 'I') or (gru.erg[3] = 'J')) THEN
  FOR x := x1 DOWNTO 0 DO BEGIN
    IF (gru.gen.ToString = '12') OR (gru.gen.ToString = '13') OR 
       (gru.gen.ToString = '14') THEN 
      fx[x] := KOL_i(x,gru) * KOL_g(x,gru) * Math.Pow(v,(w/12+1/2)) * Dx[x] * 1.05e0

the previous statement returns a wrong value into the arry fx;
the reason was w/12 returning 0 (int) and not 0.25 or 0.5 as expected.
this is described in the wiki language but obviously very error prown if you have to port 7500 + files where that is working.

      fx[x] := KOL_i(x,gru) * KOL_g(x,gru) * Math.Pow(v,(w/12.0+1/2.0)) * Dx[x] * 1.04e0

correcting the statment by making one of the two operands a double makes the statment returning the proper value; the same as openVMS PASCAL but without the 12.0 or 2.0 operands.

But often we have just two variables of type integer in which case we have to relay on the capability that the “/” is able to return a double in any case but not ZERO.

    ELSE BEGIN
      var h1 := Convert.ToDouble(Convert.ToDouble(w)/Convert.ToDouble(12));
      var h2 := Convert.ToDouble(1/2);
      var h3 := h1+h2;
      var pr := Math.Pow(v, h3 );
      fx[x] := KOL_i(x,gru) * KOL_g(x,gru) * pr * Dx[x] * 1.04e0;

// this returns the proper values in the fx array 

      END;
  END;

can you imagin how many “/” operators we have which should return a Double but never 0 for simple things like 3/12 or 6/12.

We eagerly wait for that fix. We have 7500+ code files containing such insurance and pension plan mathematics.

We tried the following: use the “div” but not the “/” divider operator
and we found in the language wicki of Oxygen the following

x := 4 div 5;

what would one expect to see as result ?
I would expect 0.8 a double; but I am wrong it returns a 0;
I tried to explicitly define x as double, but 0 is returned by 4 div 5

x := 4 div 5.0
is a compiler error, type missmatch, can not assigne Double to Integer;
So div has no value for us and can not be used as replacement for the “/” operator.

I tried to overload the Division operator named Division as per language wicki, but no lucke, I fail to implement this in absence of better examples in the language wicki.

Where do I have to place the

class operator Division(val1, val2:Double):Double

??? where does this line go if it is to be used in a simple program.
??? can I overload ether the “/” or the “div” operator and how???

thanks and regards
Josef

Are you currently using the latest beta? Thats where it was fixed (and the release for the end of the month). using the latest beta and the ‘Delphi Compatible division’ mode I get 1.5833333 for:

class method ConsoleApp.Main(args: array of String);
begin
  var w: Integer := 13;
  var x := (w/12);
  var y := (1/2);
  x := x + y;
  // add y
  Console.WriteLine('Hello World. '+x);
end;

As for operator overloading: You can only overload an operator if there’s a relation to a class you define yourself, so you can’t override it for double & double, but that’s unrelated to this.

where and how do I get the latest greatest BETA for Oxygene;
at the moment I have Oxygene for .NET 7.0.71.1477 installed with VS 2012 Ultimate.

Josef - thanks for the fast help on that.

If you have active subscription you can download betas here https://secure.remobjects.com/portal/downloads/beta.aspx

when will that fix be released with the next offical release version?

End of the month as part of the May release.

ck
thanks again
I took down the BETA version and I have tested this ‘/’ delphi compatibel division operator and it’s enabling/disabling toggel button and it works now as expected.

BUT: before I upgrade my second developer machine and other machines I will wait for the official release.
thanks again for the promt help