首页 > 编程语言 > 详细

【算法】浮点数多次运算精确值下降

时间:2019-12-08 01:04:21      阅读:104      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
int main(){
    double i=0;
    double k=10;
    for(int j=0;j<100;j++){
        i+=0.1;
    }
    printf("%d\n",i!=k);
    printf("%lf\n",i);
    printf("%lf\n",k);
    return 0;
}

 

1
10.000000
10.000000

--------------------------------
Process exited after 0.1828 seconds with return value 0
请按任意键继续. . .

结果可见多次运算的浮点数i已经和浮点数k不等

所以要多次运算浮点数时,尽量使用"<" ">"减少使用“=”

具体参考网友的博客https://blog.csdn.net/fanxueya1322/article/details/86580954

【算法】浮点数多次运算精确值下降

原文:https://www.cnblogs.com/LPworld/p/12004022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!