Interesting question. I guess someone with good knowledge on the IEEE floating point specification can give a super fast and awesome answer here. In the meantime, I can only think of a lame suggestion: Use a string stream to convert the number to string and determine if the decimal symbol is present.
But in all honesty, that is soooo lame that I wouldn't dare use it in production code. There has to be a better way.
Nice, Galik. Much more decent and clever for sure. Yes, c must be an integer for the root to have any chance of being an integer too. After all, there are no integers that squared yield a real number, and therefore if root is integer, so it is its square.
sqrt() is guaranteed to yield, I think, 1ulp precision (who has LIA-2 at hand, check), so you can simply compare to the nearest integer with appropriately-scaled epsilon. Borrowing Galik's loop:
1 2 3 4 5 6 7 8 9 10 11 12
#include <cmath>
#include <limits>
#include <iostream>
int main()
{
for(int i = 0; i < 100; ++i)
{
double root = std::sqrt(i);
if( std::abs(root - std::floor(root)) < root*std::numeric_limits<double>::epsilon() )
std::cout << i << '\n';
}
}