Float doesn't change when i add 0.1 to it

后端 未结 3 1091
感情败类
感情败类 2021-01-12 21:38

I am quite a newbie to c. So when i writing a small game demo, i face a really strange problem.

 void testC()
 {
     float a = 825300160;
     float b = a +         


        
3条回答
  •  日久生厌
    2021-01-12 22:20

    As this site shows, both a and b would be represented as

    0 10011100 10001001100010001010011
    

    in the IEEE standard for floats, where the first bit is the sign, the next 8 are the exponent, and the remaining 23 the mantissa. There's just not enough space in those 23 bits to represent the difference, because the exponent is so large.

提交回复
热议问题