Any computer Computers can only maintain represent a finite number of digits. As a result, it is impossible to precisely represent repeating binary-representation values such as 1/3 or 1/5 with 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 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 isISO/IEC WG14 has drafted a draft document in WG14 proposal to add support for decimal floating-point arithmetic to the C language\[[ISO/IEC DTR 24732|AA. C References#ISO/IEC DTR 24732]\] that proposes adding support for decimal floating-point arithmetic to the C language. |
Wiki Markup |
---|
When precise computation is necessary, carefully and methodically estimate the maximum cumulative error of the computations, regardless of whether decimal or binary is used, to ensure that the resulting error is within tolerances. Consider using numerical analysis to properly understand the numerical properties of the problem. A useful introduction can be found in \[[Goldberg 91|AA. C References#Goldberg 91]\]. |
...