In a square root function (in C) like this one:
double squareRoot(double n) {
double i, precision = 0.00001;
for(i = 1; i*i <=n; ++i); //Integer part
for(--i; i*i < n; i += precision); //Fractional part
return i;
}
what does this --i part(on line 4) do?
It works fine and for input 24, it gives 4.898980. But when this --i is replaced with just i, the result is 5.000000. Also, when i-- is used, it gives 4.898980 again. So, does that mean --i = i--? What's happening under the hood?
Also, I don't get the logic why just an i wouldn't suffice here as we're already done with the integer part. I'm a novice. Help please?