Does casting double to float always return same value?

后端 未结 6 1991
余生分开走
余生分开走 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 10:04

    A double should be able to to exactly hold every possible value of a float. Casting a float to a double should not change the value, and casting back to a float should return the original value, as long as you didn't perform any calculations on the double in the meantime.

提交回复
热议问题