- float SqrtByNewton(float x)
- {
- float val = x;//最终
- float last;//保存上一个计算的值
- do
- {
- last = val;
- val =(val + x/val) / 2;
- }while(abs(val-last) > eps);
- return val;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0403201511829.html
来源: http://www.codesnippet.cn/detail/0403201511829.html