Floating point representations seem to do integer arithmetic correctly - why?

前端 未结 8 1282
死守一世寂寞
死守一世寂寞 2021-01-06 10:41

I\'ve been playing around with floating point numbers a little bit, and based on what I\'ve learned about them in the past, the fact that 0.1 + 0.2 ends up bein

8条回答
  •  失恋的感觉
    2021-01-06 10:55

    Integers are exact because because the imprecision results mainly from the way we write decimal fractions, and secondarily because many rational numbers simply don't have non-repeating representations in any given base.

    See: https://stackoverflow.com/a/9650037/140740 for the full explanation.

提交回复
热议问题