为什么我们得到的输出为“无穷大”超出浮动范围后
我试图弄清楚,当浮点值超出范围(即大于 3.4E38)时,它的输出将为“无穷大”。我知道,当浮点数保持 max_value 时,指数位中的所有位都将保持“1”,即 11111111,一旦超过范围,它就会变成 100000000,但指数位只能保持 8 位,因此“1”将被截断,并且仅“ 00000000'将被存储在等于0的指数块中。那么,输出屏幕如何打印‘无限’?
'''
public class MyClass
{
public static void main(String args[])
{
float f=(float)3.4E+76;
System.out.println(f);
}
}
'''
I am trying to figure out, when value of float exceed's the range i.e. greater than 3.4E38 it gives the output as 'infinity'. I understand that when float holds max_value all the bits in exponent bit will be holding '1' i.e. 11111111 and as soon as it exceeds the range it becomes 100000000 but Exponent bit can only hold 8 bit so '1' will be trucated and only '00000000' will be stored in the exponent block which is equal to 0. So, how output screen prints 'infinity'?
'''
public class MyClass
{
public static void main(String args[])
{
float f=(float)3.4E+76;
System.out.println(f);
}
}
'''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无穷大(包括正无穷大和负无穷大)是浮点算术中的特殊值 如浮点标准 IEEE 754 中所定义。某些操作会产生无穷大的值,包括溢出,其格式正确为一个字符串。
正如维基百科文章的基本原理部分中所述:
Infinity (including positive and negative infinity) is a special value in floating-point arithmetic as defined in the floating-point standard IEEE 754. Certain operations produce the value infinity, including overflow, and it is appropriately formatted as a string.
As described in the rationale section of the Wikipedia article: