COMPSCI 1MD3 Lecture Notes - Lecture 10: Interval Arithmetic, Real Number
Document Summary
There are some rational numbers that cannot be written with a finite number of digits. All decimals without a finite decimal representation will not have a finite binary representation. Fractional numbers should never be compared for equality. And even if you format this, it wont amount to the right number, because the 1 gets lost in the fraction. Be careful when working with floating point numbers. Python uses 52 binary digits, approximately 16 decimal digits. Standard output gives only the first 16 decimal digits, even if conversion from binary results in more digits. ( approximate value is printed) With a finite number of digits, arithmetic operations will lead to rounding errors. In some cases, the error can get cancelled. Example of where it does not get cancelled: As a result, fractional numbers should never be compared for equality. Where the epsilon must not be too small. Consists of a fraction (mantissa) with the significant digits and an exponent.