Computer arithmetic is often imprecise. The A computer can only maintain a finite number of digits. Although floating point types can represent fractions, they are not immune to this limitation. As a result, it is impossible to precisely represent repeating binary-representation values, such as 1/3 or 1/5, in the most common floating point representation: binary floating point.
Wiki Markup |
---|
When precise computations are necessary, consider alternative representations that may be able to completely represent your values. For example, if you are performing arithmetic on decimal values and need an exact decimal rounding, represent the values in binary-coded decimal instead of using floating point. Another option is decimal floating-point arithmetic as specified by ANSI/IEEE 754-2007. There is a draft document in WG14 \[[ISO/IEC DTR 24732|AA. C References#ISO/IEC DTR 24732]\] that proposes adding support for decimal floating-point arithmetic to the C language. |
...