Easy solution: Sqr(Trunc(Sqrt(X))) = X (where X is some Integer type).

Bart

Unfortunately not :-( Internal precision of float is 56 bit mantissa. Converting a qword to float will loose the least significant 8 bit and thus provide false results in chunks of 256 consecutive numbers e.g. There is only one way to do it correct - calculate the square root with an integer based algorithm, then square it back and compare the results. The trick here is that a lot of numbers can be discarded initially just looking at the least significant n bit of the integer. Perfect squares can only have certain bit patterns in the least significant bits, so deviations can easily be discarded. However - one still needs to apply the fully check to the remaining numbers.

Background - take an integer N / then N has (in a simple case) the form 2k or 2k+1 / when squared this gives 4k^2 or 4k^2+2k+1 which leads to the bit pattern of "00" or "01" as possible least significant bits of a perfect square - so you already excluded 50% of all numbers under test. However 8 e.g. would still be considered "candidate" by this and still require the full test to be eliminated. This scheme can be expanded if one consideres N as 4k, 4+1, 4k+2, 4k+3 etc.

If you google a bit you'll probably find several implementations taking this scheme to various Levels.

Hope I made myself clear.

Cheers,

MathMan