I'm developing a simple economic system where there's a price for a certain commodity that's set each new round. The player can buy the commodity for full price, but they can sell the commodity for half-price.
Question: To determine the player's payout for selling, should I multiply by 0.5 or should I divide by 2?
If there's no difference as far as MMF2 is concerned, please say so.
If one function is more efficient - or more accurate - in certain circumstances, please say so.
Multiplying by "0.5" is exactly the same as dividing by "2.0", but dividing by "2" is technically not quite the same because, as I'm sure you know, MMF2 rounds off the result when both the values are integers rather than floats (eg. 3 / 2 = 1!).
x / 2.0 = x * 0.5
sometimes x / 2 = int(x * 0.5)
sometimes x / 2 = x * 0.5
Similarly, "Sqr(x)" and "x pow 0.5" are exactly the same.
Division's actually a little more computationally intensive, though I forgot why. I think it's because it has to be converted into doubles or something, which is done when you multiply by a non-integer anyway. So, probably the same. I'd go for whatever is easier to read. MMF2 customizes a lot of things anyway, so it might not even function as it would under CS theory.
It really doesn't matter computationally unless you're doing something with tons of math, like 20 calculations every tick, or a huge database, or every pixel in a bitmap.
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.