任何人都可以解释以下代码的数学正确性,以便在C ++中找到正数的平方根?
#include <iostream>
#include <cmath>
using namespace std;
int main(){
float a; cin>>a;
cout<<"Answer by Math library\n"<<sqrt(a)<<"\n";
//the following is the code for finding the square root of a positive double
double g=a;
while(abs(g*g-a)>1e-8){
g= (g+(a/g))/2;
}
cout<<"Answer by this algorithm\n"<<g<<"\n";
return 0;
}