## Friday, March 25, 2011

### Computer Architecture # 02 : Data Representation : THE ASSOCIATIVE LAW OF ALGEBRA DOES NOT ALWAYS HOLD IN COMPUTERS(4)

2.2.2 THE ASSOCIATIVE LAW OF ALGEBRA DOES NOT ALWAYS HOLD IN COMPUTERS
In early mathematics, we learned the associative law of algebra:
a + (b + c) = (a + b) + c
As we will see, the associative law of algebra does not hold for ﬁxed point numbers having a ﬁnite representation. Consider a 1-digit decimal ﬁxed point representation with the decimal point on the right, and a range of [-9, 9], with a = 7, b=4, and c=–3. Now a + (b + c) = 7 + (4 + –3) = 7 + 1 =8. But (a + b) + c = (7 + 4) + –3 = 11 + –3, but 11 is outside the range of our number system! We have overﬂow in an intermediate calculation, but the ﬁnal result is within the number system. This is every bit as bad because the ﬁnal result will be wrong if an intermediate result is wrong.

Thus we can see by example that the associative law of algebra does not hold for ﬁnite-length ﬁxed point numbers. This is an unavoidable consequence of this form of representation, and there is nothing practical to be done except to detect overﬂow wherever it occurs, and either terminate the computation immediately and notify the user of the condition, or, having detected the overﬂow, repeat the computation with numbers of greater range. (The latter technique is seldom used except in critical applications.)