能解释一下float 溢出吗?

chenzhanchao1016 2009-02-28 09:47:46
#include <iostream.h> //包含iostream.h头文件
main()
{

//float型溢出
float x=3.5e14;
cout<<"x="<<x<<endl;
cout<<"x*x="<<x*x<<endl;
cout<<"x*x*x="<<x*x*x<<endl;
}
运行之后结果是这样的:
x=3.5e+014
x*x=1.225e+029
x*x*x=1.#INF

为什么 会出现 x*x*x=1.#INF?能解释一下 溢出是怎么回事吗?哪溢出了?float的上界可是比这个大啊!我用的是VC++!
...全文
950 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2009-02-28
  • 打赏
  • 举报
回复
float 是4个字节32位的,
double 是8个字节64位的
qingkongyihe2008 2009-02-28
  • 打赏
  • 举报
回复
楼上正解
lzy340623339 2009-02-28
  • 打赏
  • 举报
回复
浮点型的数据存储格式是这样的:
1位(数符)n位(阶码)m位(尾数)
有些机子是32位,有些是64位,即使是64位,那62位来做阶码,2的62次幂也没有10的52次幂大呀!
所以能确定肯定是溢出了
jojotom 2009-02-28
  • 打赏
  • 举报
回复
我看的书是说float类型是4个字节32位了。
erhan_106 2009-02-28
  • 打赏
  • 举报
回复
float类型是8个字节32位的 范围应该是-2^32~2^32之间 所以后两个应该都溢出了吧
fairchild811 2009-02-28
  • 打赏
  • 举报
回复
具体可以参考http://www.math.byu.edu/~schow/work/IEEEFloatingPoint.htm
  • 打赏
  • 举报
回复
float32位,你这肯定溢出了。
fairchild811 2009-02-28
  • 打赏
  • 举报
回复
3.402823466e+38F

是float的最大值
fairchild811 2009-02-28
  • 打赏
  • 举报
回复
float的最大值没这么大
guiji1988 2009-02-28
  • 打赏
  • 举报
回复
Floating-point numbers use the IEEE (Institute of Electrical and Electronics Engineers) format. Single-precision values with float type have 4 bytes, consisting of a sign bit, an 8-bit excess-127 binary exponent, and a 23-bit mantissa. The mantissa represents a number between 1.0 and 2.0. Since the high-order bit of the mantissa is always 1, it is not stored in the number. This representation gives a range of approximately 3.4E–38 to 3.4E+38 for type float.

来自MSDN for visual studio 2008
qq675927952 2009-02-28
  • 打赏
  • 举报
回复
应该溢出了吧,都10^52 了,

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧