问题描述
我有一个我正在修改的考试题目,问题是4分。我已经认为,因为int通常是固定的长度或大小 - 存储数据的精度是有限的,其中在浮点中存储信息可以是无限的,基本上我们失去信息,因为这个
现在我有点粗略地说,我是否打了这里的正确区域。我非常确定它会失去精确度,但我不能把我的手指放在为什么。我可以获得一些帮助吗?
在Java中整数使用32位来表示其值。
在Java中,FLOAT使用23位尾数,因此大于2 ^ 23的整数将使其最低有效位被截断。例如,33554435(或0x200003)将被截断到大约33554432 +/- 4
在Java中,DOUBLE使用52位尾数,因此将能够表示32位整数而不丢失数据。
另见在维基百科上
I have an exam question I am revising for and the question is for 4 marks.
I have put that because ints are normally of fixed length or size - the precision for storing data is finite, where storing information in floating point can be infinite, essentially we lose information because of this
Now I am a little sketchy as to whether or not I am hitting the right areas here. I very sure it will lose precision but I can't exactly put my finger on why. Can I get some help, please?
In Java Integer uses 32 bits to represent its value.
In Java a FLOAT uses a 23 bit mantissa, so integers greater than 2^23 will have their least significant bits truncated. For example 33554435 (or 0x200003) will be truncated to around 33554432 +/- 4
In Java a DOUBLE uses a 52 bit mantissa, so will be able to represent a 32bit integer without lost of data.
See also "Floating Point" on wikipedia
这篇关于精度损失 - int - >浮动或双重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!