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.