Original Post
This question doesn't primarily deal with a game, however the answer of the question could be used in games and such things. Is it faster to use the computer's natural multiplication algorithm for finding a square of an integer than to use the sum of odd integers to n terms of an arithmetic series. I'm not completely sure how computers naturally work out a square but I am sure that it just multiplies the number by itself. I'm also not sure about which the multiply algorithm, but I am guessing they just add the same number 'n' times. Surely, an alternative way is to add up all the terms of an arithmetic series. For instance, the square of an integer 'n' could be calculated as follows: as opposed to: Hmm. Maybe not. It increases the amount of additions by 2. Is there any better way to square of a number? Even though I have no qualms about the speed of operations, I would like to throw some ideas into the mix about speeding up operations by the computer.
public int getSquare(int n)
{
int temp = 1;
for(int i = 1; i < n; i++)
temp+=i + i + 1
return temp;
}
public int getSquare(int n)
{
int temp = n;
for(int i = 1; i < n; i++)
temp+=n;
}