Why can't decimal numbers be represented exactly in binary?

前端 未结 20 3406
不知归路
不知归路 2020-11-21 05:15

There have been several questions posted to SO about floating-point representation. For example, the decimal number 0.1 doesn\'t have an exact binary representation, so it\'

相关标签:
20条回答
  • 2020-11-21 05:56

    A parallel can be made of fractions and whole numbers. Some fractions eg 1/7 cannot be represented in decimal form without lots and lots of decimals. Because floating point is binary based the special cases change but the same sort of accuracy problems present themselves.

    0 讨论(0)
  • 2020-11-21 05:57

    For a simple answer: The computer doesn't have infinite memory to store fraction (after representing the decimal number as the form of scientific notation). According to IEEE 754 standard for double-precision floating-point numbers, we only have a limit of 53 bits to store fraction. For more info: http://mathcenter.oxford.emory.edu/site/cs170/ieee754/

    0 讨论(0)
提交回复
热议问题