Does casting double to float always return same value?

后端 未结 6 2000
余生分开走
余生分开走 2020-12-17 09:10

Does casting double to float always produce same result, or can there be some \"rounding differences\"?

For example, is x in

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 09:47

    Considering that they have different precision, even i you're casting from less precision to wider one (I suppose that is actually your doubt) the result can not be always the same.

    Floating point operations, especially casting, are always a subject of truncating/rounding and any other type of approximation.

提交回复
热议问题