求助浮点数上溢下溢问题

suixinpiaodang suixinpiaodang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
关于C primer plus 第三章编程练习第一题的疑问。
整数的溢出弄明白了,但是对于浮点数的,还是有些不明白,麻烦有明白的讲一下。

#include<stdio.h>
int main(void)
{
int a = 2147483647;
float b = 3.40E+38;
float c = 10.0E-37f;
printf("the value of a is %d,the overflow of int is %d,the other is %d\n",a,a+1,a+2);
printf("the maxiest value of float is %e,the overflow is %e\n",b,b*10.0f);
printf("the minius value of float is %e,the overflow is %e\n",c,c/100);

return 0;
}
,结果是

浮点数倒也正常显示啊。。。我用的支持C99的编译器。。

如果把代码改成这样

#include<stdio.h>
int main(void)
{
int a = 2147483647;
float b = 3.40E+38*100.0f;

float c = 10.0E-37f/100;

printf("the value of a is %d,the overflow of int is %d,the other is %d\n",a,a+1,a+2);
printf("the maxiest value of float is %e,the overflow is %e\n",b,b*10.0f);
printf("the minius value of float is %e,the overflow is %e\n",c,c/100);

return 0;
}


结果是
上溢是正常的,下溢又不正常。。。这是什么原因呢?表示很疑惑。。
...全文
评论 8
收藏 已收藏
分享
返回顶部
suixinpiaodang
C语言 70,039 成员 243,237 内容