Write a function that computes log2() using sqrt()
来源:互联网 发布:丹江口水电站待遇 知乎 编辑:程序博客网 时间:2024/06/07 16:30
double log2(double x)
{
double l=0,r=30, lv=pow(2,l), rv=pow(2,r) ;
double m;
while(r-l>=eps)
{
m=(l+r)/2;
double mv=sqrt(lv * rv);
if(mv-x>eps) {r=m; rv=mv;}
else if(x-mv>eps) {l=m; lv=mv;}
else return m;
cout<<m<<endl;
}
return m;
}
int main()
{
double re=log2(1000);
printf("%f\n",re);
return 0;
}
0 0
- Write a function that computes log2() using sqrt()
- CareerCup Write a function that given a position returns the digit in that 0123456789101112131415..
- Write a function that takes a string as input and returns the string reversed.
- Given a function RAND5 that generates random numbers in the range 0 to 5 write a function RAND7?
- Write a program to convert string to number without using library function。
- 71.Which arithmetic operations can be performed on a column by using a SQL function that is built in
- How can I deliver parameters to a test function, that launched using adb shell am Instrumentation co
- ToXML. A function that creates XML
- 【Hacker Rank】07.Write a function
- Write a method that returns all subsets of a set.
- Write a method that returns all subsets of a set
- Fast Integer Log2 function in C/C++
- log2
- log2
- log2
- A sample that using the completion port I/O model
- Overriding Method Using Parameter That is a Subclass?
- Using OpenMP (一) Write a multi threaded program
- 2014网易游戏实习生面试体验
- Oracle中主键递增
- hdu1301&poj1251 Jungle Roads(最小生成树之prim果题)
- Cocos2d-x v3.1 GUI系统--环境构建(七)
- 并发过10万的TCP请求 ,对Linux内核优化配置
- Write a function that computes log2() using sqrt()
- 希尔排序(ShellSort)
- servlet调用的几种方式
- [Twitter] Given a matrix with all elements sorted on each individual row and column find
- 数据挖掘领域顶级会议期刊及其分析
- ajax,jquery,$.post/$.get异步刷新div,局部刷新页面
- C++基础(六)一个Class
- 使用了<input type="submit" value="Submit" onclick="this.disabled=true" />不能提交
- 开启 J2EE(六)— Servlet之Filter详解及乱码处理实例