丢失精度分配浮点值? [英] Loss of precision assigning floating point values?
问题描述
如何检查浮点数到双精度(反之亦然)
是否会导致精度损失?
BigMan写道:如何判断浮点数为double(反之亦然)
是否会导致精度损失?
将float赋值给double总是精确的。将
a double分配给一个浮点数会导致精度损失,如果双尾数在其尾数部分超出
的范围内有非零位数。浮动的
尾数。没有平台无关的支票
你可以做,这一切都取决于浮动的表示和
双重类型。
V
Victor Bazarov写道:BigMan写道:如何检查float的赋值是否为double(或者反$ b $反之亦然)会导致精度损失?
将float赋值给double总是精确的。如果double在其尾部的部分中具有超过浮点数的尾数大小的非零位,则将双精度分配给浮点将导致精度损失。没有平台无关的检查,你可以做,这一切都取决于浮动和
双重类型的表示。
V
double d = ...;
float f =(float)d;
bool loss =(d!=(double)f );
?
问候,
Bogdan Sintoma
Bogdan Sintoma写道:Victor Bazarov写道:
BigMan写道:
我怎样才能检查是否将浮点数赋值为double(或者反之亦然)
会导致精度损失?
将浮点数分配给双精灵总是精确的。如果double在其尾部的部分中具有超过浮点数的尾数大小的非零位,则将双精度分配给浮点将导致精度损失。没有平台无关的检查,你可以做,这一切都取决于浮动和
双重类型的表示。
V
double d = ...;
float f =(float)d;
bool loss =(d!=(double)f);
?
我认为这可以衡量如果分配_has_resulted_失去了
精度,而不是它_will_结果,你不同意吗?
V
How can I check if assignment of a float to a double (or vice versa)
will result in loss of precision?
BigMan wrote:How can I check if assignment of a float to a double (or vice versa)
will result in loss of precision?
Assignment of a float to a double is always precise. Assignment of
a double to a float will cause loss of precision if the double has
non-zero bits in the part of its mantissa beyond the size of the
mantissa of the float. There is no platform-independent check that
you could do, it all depends on the representation of the float and
double types.
V
Victor Bazarov wrote:BigMan wrote:How can I check if assignment of a float to a double (or vice versa) will result in loss of precision?
Assignment of a float to a double is always precise. Assignment of
a double to a float will cause loss of precision if the double has
non-zero bits in the part of its mantissa beyond the size of the
mantissa of the float. There is no platform-independent check that
you could do, it all depends on the representation of the float and
double types.
V
double d = ...;
float f = (float)d;
bool loss = (d != (double)f);
?
Regards,
Bogdan Sintoma
Bogdan Sintoma wrote:Victor Bazarov wrote:BigMan wrote:How can I check if assignment of a float to a double (or vice
versa)
will result in loss of precision?
Assignment of a float to a double is always precise. Assignment of
a double to a float will cause loss of precision if the double has
non-zero bits in the part of its mantissa beyond the size of the
mantissa of the float. There is no platform-independent check that
you could do, it all depends on the representation of the float and
double types.
V
double d = ...;
float f = (float)d;
bool loss = (d != (double)f);
?
I think this measures if the assignment _has_resulted_ in a loss of
precision, not if it _will_ result, don''t you agree?
V
这篇关于丢失精度分配浮点值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!