Best moments to apply pow in games

Continue with the course i am very excited to learn this kind of things (well to refresh the knowledge :slight_smile: ) . I did the exercise that Rick has explained in the video

and applying rounded methods like round, ceil or floor i can not see any change, my questions here are the next:

  1. if in into my game i have a big result from a pow operation it worth to apply rounded method to see differences in the final result?

  2. where is the best place in game to apply squaring, cubing , pow?

Hi @williamsnieves.
The reason you’e not really seeing any difference when rounding with things like floor or ceiling is because when you raise a whole number to some power, the result will always be an integer.

Before you round any of your values, think about why you might be doing it and be careful of accidentally introducing rounding errors if you plan to use the values for another calculation down the road.

As for seeing a difference in rounding large numbers, it depends on what you mean.
If you’re just storing a number in say an int, then it doesn’t really matter what that number is. It’ll take up the same amount of memory regardless and your programming language won’t really care whether than number has been rounded or not.
If you’re number is larger than what an int can store, then there are larger data types that may be able to store it. Otherwise, you’d probably turn to scientific notation, which is something we touch on in a later lecture. In that case you’d use an approach that does include some rounding but you’d break the number into two parts.

When it comes to taking about the “best” place to apply exponents, it depends on your game and what you’re trying to achieve. If you need to multiply a number by itself multiple times then it can be easier to use the Pow function - imagine having to write out 2 * 2 * 2 * … 24 times!

1 Like

@garypettie thanks for the answer it’s clarifying my doubts a lot. I will try to apply this kind of things in my games and then we will see the results :stuck_out_tongue:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms