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

前端 未结 4 1404
一个人的身影
一个人的身影 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条回答
  •  -上瘾入骨i
    2021-01-31 22:42

    If you look at the matter in simple terms, it is about how data has been represented by original designers.

    ideally bit depth of long(64) is larger than float(32). But float data has represented using scientific notion which allows to represent considerably much larger range

    Ex: 300[original number] : 3×102 [scientific representation]


    Long : -2^63 to 2^63-1

    Float : (-3.4)*10^38 to (3.4)*10^38

    Notice the Long(power of two) Vs Float(power of ten) representational difference here which allow float to have higher range

    hope this is helpful

提交回复
热议问题