How many significant digits do floats and doubles have in java?

前端 未结 6 1436
余生分开走
余生分开走 2020-11-22 09:28

Does a float have 32 binary digits and a double have 64 binary digits? The documentation was too hard to make sense of.

Do all of the bits translate to significant d

6条回答
  •  礼貌的吻别
    2020-11-22 09:47

    Look at Float.intBitsToFloat and Double.longBitsToDouble, which sort of explain how bits correspond to floating-point numbers. In particular, the bits of a normal float look something like

     s * 2^exp * 1.ABCDEFGHIJKLMNOPQRSTUVW
    

    where A...W are 23 bits -- 0s and 1s -- representing a fraction in binary -- s is +/- 1, represented by a 0 or a 1 respectively, and exp is a signed 8-bit integer.

提交回复
热议问题