The Daily Click ::. Forums ::. Klik Coding Help ::. Division or Multiplication
 

Post Reply  Post Oekaki 
 

Posted By Message

s-m-r

Slow-Motion Riot

Registered
  04/06/2006
Points
  1078

Candle
18th November, 2012 at 18/11/2012 01:45:35 -

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.

Thanks for your help, folks!

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
18th November, 2012 at 18/11/2012 03:10:42 -

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.

Edited by Sketchy

 
n/a

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
19th November, 2012 at 19/11/2012 08:33:01 -

IIRC, MMF doesn't use floats, it uses doubles.

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.

Image
   

Post Reply



 



Advertisement

Worth A Click