Distance between two points:
sqrt((x1-x2)^2 + (y1-y2)^2)
No, if you need the exact distance you cannot beat that formula.
Although to be clear ^ is not an operator for squaring a value, but a bit operator that does xor.
you will need something like
double dx = (x2-x1); double dy = (y2-y1); double dist = sqrt(dx*dx + dy*dy);
If you can live with just the square (which is useful when you just want to do something like sort by distance, you can use the much more efficient
double dx = (x2-x1); double dy = (y2-y1); double dist = dx*dx + dy*dy;
These will be at least as good as a solution pow. At worst, pow() will use the stack and be less efficient, but maybe your compiler turns it into x*x for this case.