TutorChase logo
Login
AQA A-Level Computer Science

14.4.5 Rounding Errors

Rounding errors occur when binary systems cannot exactly represent or store a number, leading to slight inaccuracies in fixed-point and floating-point representations.

What is a rounding error?

A rounding error is the small difference between a number's true value and its binary representation. Computers use binary (base-2) rather than decimal (base-10), and only a limited number of bits can be used to store numbers. As a result, many decimal values cannot be represented precisely and must be rounded or truncated. These inaccuracies can affect calculations, particularly when precision is important or when operations are repeated.

Rounding errors are not always noticeable, but over time or across multiple operations, they can accumulate and lead to significantly incorrect results. Understanding how and why these errors occur is essential in computer science and helps in making informed decisions when designing algorithms or systems involving numerical computation.

Rounding in fixed-point binary representation

What is fixed-point representation?

Take your grades to the next level!

UPGRADING TO PREMIUM UNLOCKS
AI Tutor
AI-powered study assistant
instant feedback and guidance
Predicted Papers
Examiner-style predicted papers
based on recent exam trends
Practice Questions
All exam practice questions
by topic for each subject
Study Notes
All detailed revision notes
written by expert teachers
Cheat Sheets
Quick revision summaries
perfect for last-minute review
Past Papers
Complete collection
of practice and past exam papers
Email
Password
Confirm Password
Already have an account?

Practice Questions

FAQ

Rounding errors affect comparisons because floating-point numbers may not store the exact value expected. For example, comparing two values such as x 0.1 may return false even if x was calculated using repeated additions of 0.01, due to minor inaccuracies caused by rounding. These tiny discrepancies mean two values that appear equal when printed may not be identical at the binary level. This is a common issue when using equality () or inequality (!=) operators. To handle this safely, a common technique is to compare the difference between two numbers to a small value called epsilon. For example, use if abs(x - 0.1) < 0.00001: to allow for minor rounding differences. This approach, known as approximate comparison, ensures that results are accurate within a tolerance range, and avoids incorrect logic in conditional statements caused by insignificant rounding differences.

Yes, rounding errors can cause instability in certain algorithms, particularly those involving many repetitive operations, very large or very small numbers, or operations where values of similar magnitude are subtracted. Numerical algorithms in fields like physics, engineering, and data science are especially vulnerable. Examples include solving systems of linear equations, integrating functions, or performing matrix operations. In such cases, small rounding errors can accumulate rapidly, magnify through each operation, and lead to incorrect or unstable outcomes. This is known as numerical instability. Algorithms involving ill-conditioned problems—where small changes in input lead to large changes in output—are also highly sensitive to rounding. To minimise this, techniques such as reordering operations, using double precision, or applying error-compensated algorithms like Kahan summation are used. Carefully designing algorithms with rounding behaviour in mind is crucial for maintaining reliable and predictable results in complex calculations.

The order of operations in binary arithmetic can significantly influence the total rounding error due to the way binary approximations behave. When adding or subtracting numbers of vastly different magnitudes, the smaller number may be lost entirely due to lack of precision—a problem known as loss of significance. For example, adding 0.0000001 to 1000000 may have no effect in binary floating-point if the smaller value is beyond the precision limit of the mantissa. Rearranging operations to group similar-sized numbers together first can reduce the impact of rounding. For example, instead of adding numbers in the order A + B + C, it may be better to group smaller terms (B + C) first. This helps preserve significance and reduces error propagation. Additionally, using associative operations like addition in a consistent and thoughtful order ensures that errors do not magnify unpredictably, making the algorithm more stable and reliable.

Guard bits, round bits, and sticky bits are additional bits used in hardware-level floating-point arithmetic to improve the accuracy of rounding and reduce error. These extra bits extend beyond the mantissa and are not stored as part of the final result but are used temporarily during calculations. The guard bit is the first bit after the least significant bit (LSB) of the mantissa, used to indicate if rounding is needed. The round bit is the bit following the guard bit and helps determine the direction of rounding. The sticky bit is set if any bits beyond the round bit are 1, indicating whether there was any discarded information. These three bits help implement various rounding modes, such as round-to-nearest or round-toward-zero, more accurately. By using them, hardware can round numbers in a way that minimises total rounding error and improves the reliability of arithmetic operations, particularly in high-performance computing.

Rounding errors generally do not occur in integer arithmetic, because integers are stored exactly within the range allowed by their bit size. For example, an 8-bit unsigned integer can represent values from 0 to 255 without any approximation. Every operation—addition, subtraction, multiplication—produces an exact result, unless the result exceeds the representable range, which leads to overflow, not rounding. In contrast, both fixed-point and floating-point representations involve fractional components that cannot always be stored precisely, especially when the binary form of a decimal is recurring or too long for the bit allocation. These formats approximate real numbers, leading to rounding errors. Additionally, real number representations are affected by the limitations of the mantissa (in floating-point) or fractional bits (in fixed-point), making them susceptible to precision loss. Thus, while integer arithmetic is exact and predictable within bounds, binary real number arithmetic involves constant trade-offs between range and precision.

Hire a tutor

Please fill out the form and we'll find a tutor for you.

1/2
Your details
Alternatively contact us via
WhatsApp, Phone Call, or Email