牛顿迭代法

1.用途:求平方根

2.实现:

 1 int NewtonSqrt(int x){
 2     double xi, x0 = x, C = x;
 3     if (!x) return 0;
 4     while (1){
 5         xi = 0.5 * (x0 + C / x0);
 6         if (fabs(x0 - xi) < 1e-7) break;
 7         x0 = xi;
 8     }
 9     return x0;
10 }

3.参考资料:

https://www.cnblogs.com/houkai/p/3332520.html

https://leetcode-cn.com/problems/sqrtx/solution/

上一篇:再谈arcgis portal的CORS


下一篇:创建编译环境_编译OPENWRT固件_用SDK为官方固件编译第三方软件3proxy