Sqrt double
来源:互联网 发布:淘宝订单险是什么意思 编辑:程序博客网 时间:2024/06/07 02:12
EPI: https://code.google.com/p/elements-of-programming-interviews/source/browse/trunk/Square_root.cpp
public static double sqrt(double num) { double left = 0, right = 0; if (num < 1) { left = num; right = 1; } else { left = 1; right = num; } while (left < right) { double m = left + (right-left)/2; if ((num-EPSILON)/m <= m && (num+EPSILON)/m >= m) { return m; } else if ((num-EPSILON)/m > m) { left = m; } else { right = m; } } return num; }
Newton's method
f(x0)' = f(x0)/(x-x0)
x = x0/2+num/2x0 (the following code replaces x with y, num with x)
public static double sqrtNewton(double num) { double x = num; double y = x/2; while (Math.abs((num-y*y)) > EPSILON) { y = (x/y+y)/2; } return y; }
0 0
- Sqrt double
- Sqrt(int x) &&Sqrt(double x)
- k=(int)sqrt((double)m); 是什么意思
- sqrt
- sqrt
- sqrt
- sqrt
- sqrt
- sqrt
- sqrt
- C语言的那些事——sqrt()函数 和 double型数据的“%lf”
- 【POJ1751】【坑,double 不能用memset】【sqrt i j写错了】
- pow函数与sqrt函数的返回值为double型
- java 中Math.sqrt()使用注意事项 Type mismatch: cannot convert from double to float
- Double
- Double
- double
- Java编程对于Math里的sqrt与pow的double数据的相等问题——BigDecimal和 DecimalFormat实现
- 每个程序员需掌握的20个代码命名小贴士
- [LinkedIn] Smallest/greatest/largest k element in stream of data (integer array) priority Q / heap
- P52第21题
- JS实现页面跳转 浏览器地址栏保持不变
- cJSON源码解释(一)--节点管理
- Sqrt double
- linux 查看用户所在组(groups指令的使用) 含实例
- 8.3 时间戳(Time Stamp)选项
- Linux下chkconfig命令详解
- 黑马程序员——Foundation框架学习——OC结构体、字符串、OC集合、NSNumber,NSValue、OC时间对象
- 复习——几种排序实现
- declare-styleable中format详解
- iOS开发 GPS定位 指定语言 返回中文地点
- 第8题