H
Howard
Gaijinco said:The issue at hand was that I would normally do this for testing if an
integrer was a square number:
bool square_number(int number){
if(sqrt(number)==floor(sqrt(number)))
return true;
else
return false;
}
However "sqrt(number)==floor(sqrt(number))" seemed an awkward way to
test it, so I wasn't sure if there was a "clenear" way to do it.
No sense computing the square root twice. You could store the result of
sqrt() in a float (or double) and compare that against the floor() of
itself.
There are also integer techniques for testing if a number is a perfect
square, but those may not be significantly faster in practice (if that's
even an issue).
-Howard