Understanding floating point representation errors; what's wrong with my thinking?

后端 未结 5 1681
再見小時候
再見小時候 2020-12-11 06:15

I\'m having some trouble understanding why some figures can\'t be represented with floating point number.

As we know, a normal float would have sign bit, exponent,

5条回答
  •  醉话见心
    2020-12-11 06:54

    You're thinking about 1* 10^-1, which works for a decimal floating number representation, such as decimal in C#. The normal floating point (such as float, double) uses binary representation, i.e. in powers of 2

    Normally, binary is used because they can be more efficiently arranged in bits. Decimal is normally used when absolute decimal precision is required, for example when counting money.

提交回复
热议问题