浮动可以通过双重循环而不丢失精度? [英] Can float be round tripped via double without losing precision?
问题描述
如果我有一个C# float
,可以将它转换为 double
,而不会丢失任何精度?
如果 double
被转换回 float
,它会有完全相同的值吗?
是的。 IEEE754浮点(这是C#必须使用的)保证了这一点:
$ b
-
转换一个
float code>到
double
完全保留相同的值 -
将
double
转换回为float
正好 原始 Converting a
float
to adouble
preserves exactly the same valueConverting that
double
back to afloat
recovers exactly that originalfloat
.
double s是 float的超集。 s。
请注意, >适用于 NaN
, + Infinity
和 -Infinity
。零的签名也被保留。
If I have a C# float
, can I convert it to double
without losing any precision?
If that double
were converted back to float
, would it have exactly the same value?
Yes. IEEE754 floating point (which is what C# must use) guarantees this:
The set of double
s is a superset of float
s.
Note that this also applies to NaN
, +Infinity
, and -Infinity
. The signedness of zero is also preserved.
这篇关于浮动可以通过双重循环而不丢失精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!