🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Compile Math Operator First Attempts Casting

Started by
1 comment, last by WitchLord 10 years, 4 months ago

What do you think of modifying the CompilerMathOperator function in the following way? When an non-primitive type and a primitive type are involved in a binary math operator, the non-primitive type is currently being converted to the primitive type. I propose first attempting to convert the non-primitive type to any primitive type that is can implicitly cast.

I have several types which implicitly convert themselves to double. Script writers often use integer literals in place of double literals when the number is exactly an integer. This leads to some undesirable results.


MyValue x = 3.5;

double y = x * 2;  // result == 6 rather than the expected 7.

The operator attempts conversion to an integer, which ultimately invokes the implicit cast to a double, but then it converts that result to an integer before multiplication.

I have attached a patch that implements my suggestion.

Advertisement

It sounds reasonable.

I'll look into the patch.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've added this in revision 1862.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement