Advertisement

Compile Math Operator First Attempts Casting

Started by February 17, 2014 02:58 PM
1 comment, last by WitchLord 10 years, 8 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.

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

Advertisement

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