Jump to content
  • Advertisement
Sign in to follow this  
Jason Goepel

Compile Math Operator First Attempts Casting

This topic is 2056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!