Why does changing the sum order returns a different result?

后端 未结 6 1378
别那么骄傲
别那么骄傲 2020-11-30 16:18

Why does changing the sum order returns a different result?

23.53 + 5.88 + 17.64 = 47.05

23.53 + 17.64 + 5.8

6条回答
  •  眼角桃花
    2020-11-30 17:16

    I believe it has to do with the order of evaulation. While the sum is naturally the same in a math world, in the binary world instead of A + B + C = D, it's

    A + B = E
    E + C = D(1)
    

    So there's that secondary step where floating point numbers can get off.

    When you change the order,

    A + C = F
    F + B = D(2)
    

提交回复
热议问题