浮动可以通过双重循环而不丢失精度? [英] Can float be round tripped via double without losing precision?

查看:194
本文介绍了浮动可以通过双重循环而不丢失精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个C# float ,可以将它转换为 double ,而不会丢失任何精度?

如果 double 被转换回 float ,它会有完全相同的值吗?

解决方案

是的。 IEEE754浮点(这是C#必须使用的)保证了这一点:
$ b


  1. 转换一个 float code>到 double 完全保留相同的值


  2. double 转换回为 float 正好 原始




  3. 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:

    1. Converting a float to a double preserves exactly the same value

    2. Converting that double back to a float recovers exactly that original float.

    The set of doubles is a superset of floats.

    Note that this also applies to NaN, +Infinity, and -Infinity. The signedness of zero is also preserved.

    这篇关于浮动可以通过双重循环而不丢失精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆