Numerical Methods · Numerical Methods
Numbers and Errors: Binary Representation and Error Theory
Explanation
Why Does a Computer Make Arithmetic Mistakes?
Try it yourself: ask a computer to compute . The result is not but . How can a computer, seemingly capable of perfect precision, make a mistake on simple addition?
The answer lies in how computers represent numbers. All numbers in a computer are stored in binary form — as sequences of 0s and 1s — and most decimal numbers we are familiar with cannot be represented exactly in binary. This is the source of errors we will learn to characterize and control.
Binary Representation of Integers
In the binary numeral system (base 2), each digit (bit) represents a power of 2:
where .
Decimal to Binary Conversion
To convert an integer to binary: repeatedly divide by and record the remainders from bottom to top.Example: :
Reading upward: . Verification: ✓
Binary to Decimal Conversion
Simply: .Binary Representation of Fractions
For the fractional part: repeatedly multiply by and collect the integer parts.
Example: :
Therefore . Verification: ✓
The problem: For :
So — an infinite repeating expansion! It cannot be stored exactly in a finite number of bits.
Floating-Point Representation — IEEE 754 Standard
Computers store real numbers in the form:
where:
- — sign bit (0 = positive, 1 = negative)
- — mantissa: the bits after the binary point
- — biased exponent
Single precision (float32): 1 sign bit, 8 exponent bits (bias = 127), 23 mantissa bits. Total: 32 bits.
Double precision (float64): 1 sign bit, 11 exponent bits (bias = 1023), 52 mantissa bits. Total: 64 bits.
Machine Epsilon
Machine epsilon is the smallest number such that in floating-point arithmetic.where is the number of mantissa bits (including the implicit leading "1."). For float64: , so:
Sources of Error and Error Theory
Definitions
- Absolute error: , where is the true value and is the approximation.- Relative error: (defined when ).
Sources of Error
1. Rounding error: Originates from the finite binary representation — every number is rounded to the nearest representable value.2. Truncation error: When an infinite process (such as a Taylor series) is cut off at finitely many terms.
3. Propagation error: Errors in input data are amplified through arithmetic operations.
4. Instability: Some algorithms amplify small errors, and are therefore not numerically stable.
Rule of Thumb
In double precision, for typical computations, the relative error is on the order of to .Catastrophic Cancellation
A dangerous phenomenon: when two nearly equal numbers are subtracted, significant digits are lost.Example: , . In float64:
But if both numbers were measured with relative error , the result could be zero — total loss of precision.
Example: Computing Square Roots
Solving with the standard formula can suffer from catastrophic cancellation when .
Remedy: For the at-risk root, use the alternative formula:
This avoids catastrophic cancellation in both roots.
Interactive Visualization
Loading visualization
Worked Examples
Practice
Exercise 1 of 6
1
Convert the number to decimal. What is the value?
★Quiz
Test your knowledge from this lesson
A mix of questions from the lesson — each attempt varies slightly
Answer at least 4 out of 5 questions correctly to pass (70%)