What types of numbers are representable in binary floating-point?

后端 未结 4 1030
广开言路
广开言路 2020-11-30 02:35

I\'ve read a lot about floats, but it\'s all unnecessarily involved. I think I\'ve got it pretty much understood, but there\'s just one thing I\'d like to know for

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 03:10

    Floating-point numbers are literally represented using the form:

    1.m * 2^e
    

    Where 1.m is a binary fraction and e is a positive or negative integer.

    As such, you can represent 1/32 + 1/16 exactly, as:

    1.1000000 * 2^-4
    

    (1.10 being the binary fraction equivalent to 1.5.) 1/48, however, is not representable in this format.

提交回复
热议问题