1.不能用%d输出double类型的数

     double a1=5.3;
double a2=1234.1234;
double a3=3412341.12341234; double b1=1.5;
double b2=123.5;
double b3=23412.5; double c1=10.7;
double c2=2.9;
double c3=3241324.56251;
printf("%d\n",a1);
printf("%d\n",a2);
printf("%d\n",a3); printf("%d\n",b1);
printf("%d\n",b2);
printf("%d\n",b3); printf("%d\n",c1);
printf("%d\n",c2);
printf("%d\n",c3);

输出的值不会变

2.

float pow(float x, float y)

x,y可以为整形,因为进行时会自动转换类型,

但是用%d输出double类型的数则不行。

可以使用(int)。

     cout<<pow(,)<<endl;
cout<<pow(,)<<endl;
cout<<pow(,)<<endl; printf("\n"); printf("%f\n",pow(,));
printf("%f\n",pow(,));
printf("%f\n",pow(,)); printf("\n"); printf("%d\n",pow(,));
printf("%d\n",pow(,));
printf("%d\n",pow(,)); printf("\n"); printf("%d\n",(int)pow(,));
printf("%d\n",(int)pow(,));
printf("%d\n",(int)pow(,));

3.

float log(float x)

(int)使用在在(int)右边的第一个整数。

所以不能使用(int)log(s)/log(2),而是(int)(log(s)/log(2))。

而求log(2^k)/log(2)时,出现问题,因为是精度不准的问题,如结果为1.99..9xxxd,用(int)后结果为1。

可以采用log(2^k+minv)/log(2)解决,minv=1e-12(或其它)。

     printf("%.15f\n",log()/log());
printf("%.15f\n",log()/log());
printf("%.15f\n",log()/log());
printf("%.15f\n",log()/log());
printf("%.15f\n",log()/log()); printf("\n"); printf("%f\n",(int)log()/log());
printf("%f\n",(int)log()/log());
printf("%f\n",(int)log()/log());
printf("%f\n",(int)log()/log());
printf("%f\n",(int)log()/log()); printf("\n"); printf("%d\n",(int)(log()/log()));
printf("%d\n",(int)(log()/log()));
printf("%d\n",(int)(log()/log()));
printf("%d\n",(int)(log()/log()));
printf("%d\n",(int)(log()/log()));
printf("%d\n",(int)(log()/log()));
printf("%d\n",(int)(log()/log())); printf("\n"); printf("%d\n",(int)(log(+minv)/log()));
printf("%d\n",(int)(log(+minv)/log()));
printf("%d\n",(int)(log(+minv)/log()));
printf("%d\n",(int)(log(+minv)/log()));
printf("%d\n",(int)(log(+minv)/log()));
printf("%d\n",(int)(log(+minv)/log()));
printf("%d\n",(int)(log(+minv)/log()));

pow log 与 (int)的更多相关文章

  1. leetcode Pow(doubule x,int n)

    今天第一天开通博客,心情还是小激动的 上代码: 方法一:常规递归,x的n次方={xn/2*xn/2              //n为偶 xn/2*xn/2 *x          //n为奇数 } ...

  2. 50. Pow(x, n) (INT; Divide-and-Conquer)

    Implement pow(x, n). 思路:二分法,将每次相乘,转化成平方. class Solution { public: double myPow(double x, int n) { ) ...

  3. leetcod Pow(x, n)

    题目:就是实现一个指数函数. 直接用一个while一直乘以n词肯定是会超时的. 自己写了用递归(而且是很挫的递归),测试了无数次,根据每个case去修改代码.终于可以AC了.不忍直视,自己写了好长,如 ...

  4. [LeetCode] 数学计算模拟类问题:加法,除法和幂,注意越界问题。题 剑指Offer,Pow(x, n) ,Divide Two Integers

    引言 数学计算的模拟类题目,往往是要求实现某种计算(比如两数相除),实现的过程中会有所限定,比如不允许乘法等等. 这类题目首先要注意计算过程中本身的特殊情况.比如求相除,则必须首先反映过来除数不能为0 ...

  5. leetcode 二分法 Pow(x, n)

    Pow(x, n) Total Accepted: 25273 Total Submissions: 97470My Submissions Implement pow(x, n). 题意:求x的n次 ...

  6. leetcode || 50、Pow(x, n)

    problem: Implement pow(x, n). Hide Tags Math Binary Search 题意:求x的n次幂 thinking: (1)最简单想到的是直观上的数学幂函数求法 ...

  7. 多项式FFT/NTT模板(含乘法/逆元/log/exp/求导/积分/快速幂)

    自己整理出来的模板 存在的问题: 1.多项式求逆常数过大(尤其是浮点数FFT) 2.log只支持f[0]=1的情况,exp只支持f[0]=0的情况 有待进一步修改和完善 FFT: #include&l ...

  8. Pow(x, n)

    Implement pow(x, n). public class Solution { public double pow(double x, int n) { //判断x是不是0 if(Math. ...

  9. leetcode pow(x,n)实现

    题目描述: 自己实现pow(double x, int n)方法 实现思路: 考虑位运算.考虑n的二进制表示形式,以n=51(110011)为例,x^51 = x^1*x^2*x^16*x^32,因此 ...

随机推荐

  1. SCRUM 12.21

    从爬虫遇到的问题中我们学会了: 1.有的网站是有反爬虫机制的,外卖网站(我们猜测基本所有盈利性质的网站可能都是)全部都有. 2.我们对于反爬虫机制有了一定的了解.   本次爬虫测试中,我们最后连美团网 ...

  2. 个人阅读作业 --软件工程M1/M2总结

    软件工程M1/M2总结 写在前面的话: 这学期的软件工程伴着考期的展开逐渐落下帷幕,回顾这学期的软件工程,我感觉我的热情在一次又一次的失落中逐步消耗殆尽,每个人对于这门课的体验都会有所不同吧,可以确定 ...

  3. Struts2中的图片验证码

    1.Struts中建一个action <action name="Code" class="LoginAction" method="code& ...

  4. how-is-docker-different-from-a-normal-virtual-machine[Docker与VirtualMachine的区别]

    https://stackoverflow.com/questions/16047306/how-is-docker-different-from-a-normal-virtual-machine 被 ...

  5. Activiti reassign task to another user

    //早先胡乱尝试的其他方法,可能对于以后深入学习Activiti有些用处. //taskService.delegateTask(taskId, receiveUserId); //taskServi ...

  6. Java 泛型 1例

    private <T> T getFirstItem(List<T> list) {        T item = null;        if(list != null ...

  7. DELPHI XE10,JSON 生成和解析,再利用INDYHTTP控件POST

    Delphi XE10,Json 生成和解析,再利用indyhttp控件Post 年09月20日 :: 阅读数: --不多说,直接上代码 procedure TFrmMain.Brand; var J ...

  8. Robot Framework 入门教程总结

    Robot Framework 作为一款通用测试框架,可加载多种测试库.驱动多种测试工具,并可对各种自定义脚本进行集成.对于Robot Framework,我准备将其分为 入门--Robot Fram ...

  9. [转帖] ASP ASPX 等知识

    asp.asp.net..aspx..ascx..ashx的简单说明 https://www.cnblogs.com/jhcelue/p/6736147.html ASP是动态server页面(Act ...

  10. Chrome disable cache & clear memory cache

    Chrome disable cache & clear memory cache disable cache