uxmal / pytocs

Converts Python source to C#
Apache License 2.0
556 stars 167 forks source link

Python integers division should give a C# result of float/double type #16

Open BrunoGagnon-Eaton opened 6 years ago

BrunoGagnon-Eaton commented 6 years ago

Currently, the code is just forwarded ‘as is’ during conversion and gives a C# result of type integer. The problem appy to Python (3.x and more).

Example:

Py: b=3; r= 1/b # r = 0.3333333333333 C#: int b=3; var r= 1/b; // r = 0 !!! C# (expected example): int b=3; var r= 1/(float)(b); // r = 0.3333333333333

uxmal commented 6 years ago

Should be easy enough to fix

uxmal commented 6 years ago

On second thought, I will leave this open until Python type inference is completed. I don't want to sprinkle unnecessary casts in the code if pytocs can prove a variable is a numeric type that will be promoted to floating point by the C# compiler.