I recently tried to port some managed Direct X code from Delphi to Chrome.
After all the code compiled, when it ran it did not behave in the same was as the Delphi.NET version ( I'm talking about the PointSprites demo ).
After about 2-3 hours of racking my brain ( I know I'm a bit slow up top ) and stepping through nearly all the code, it turns out that in Chrome, the / operator works like div if 2 integers are used.
For example :
[pascal]
var
fRand1 : Single;
FRand : System.Random;
begin
FRand := new System.Random;
fRand1 := (FRand.Next(int32.MaxValue)/int32.MaxValue) * Math.PI * 2.00;
end;
[/pascal]
fRand1 will always equal 0 because int32.MaxValue is always an integer so the expression
[pascal](FRand.Next(int32.MaxValue)/int32.MaxValue)[/pascal]
equates to *zero*.
The only way to ensure a floating point value is to do what you do in C# or C/C++ which is to typecast at least one of the integer values like this...
[pascal]fRand1 := (Single( FRand.Next(int32.MaxValue) ) / int32.MaxValue) * Math.PI * 2.00;
[/pascal]
I have suggested to RemObjects, that this is quite a fundamental Pascal change that will break a fair amount of existing Pascal code if people decide to port to Chrome, but the RO team believes that consistency of mathematical operations is more important.
I personally think that this makes Chrome a Next Gen C#, rather than a Next Gen Object Pascal, but after all it is his company and his compiler, so he can do what ever he likes.
This is quite significant for us game developers, as a lot of us reuse algorithms from other projects and game development is all about the maths, hence why this is posted here as a sticky thread.
So please be aware of this fact when porting your code to Chrome.
It will save you some head scratching if you come from an Object Pascal background.
Bookmarks