Java Why is converting a long (64) to float (32) considered widening?

前端 未结 4 1413
一个人的身影
一个人的身影 2021-01-31 22:08

As it states from oracle

Reference from Oracle Docs

Widening Primitive Conversion 19 specific conversions on primitive types are called

4条回答
  •  借酒劲吻你
    2021-01-31 22:44

    It is considered widening because the numbers that can be represented by a float is larger than numbers that can represented by long. Just because float uses 32 bit precision does not mean the numbers it can represent are limited to 2^32.

    For instance the float (float)Long.MAX_VALUE+(float)Long.MAX_VALUE is larger than Long.MAX_VALUE, even though the float has less precision that the long.

提交回复
热议问题