1

I am trying to understand tthe associativity of operations when it comes to floating points. In the lecture notes i have, the following is stated:

"suppose floating-point values store seven digit of accuracy. Considee the problem of adding 11 numbers together, where one of the numbers is 10^7 and the other ten are 1.

If the small numbers (the 1s) are each added to the large number, one at a time, there is no effect on that number, because the small numbers occur in the eighth digit of the large number ". So here I understood that the result is 1,000,001.

"however, if the small numbers are first added together and the result is added to the large number, the result is a seven-digit accurancy 1.000001 * 10^7"

But both approaches seemed the same to me: we are adding the 10 numbers to the larger number. Can someone please clarify this problem ? Thank you

abedzantout
  • 802
  • 4
  • 15
  • 28

1 Answers1

3

Let's go over the first method first. When the small numbers are added one by one to the large number, the following will happen ten times:

10,000,000 + 1 = 10,000,001

However since the floating-point values store only seven digits of accuracy this last digit, the eight digit, will be rounded in the seventh digit to zero. This operation will happen 10 times, and so the value will remain 10,000,000.

Next let's go over the second method. The 10 number 1's are added together first and so this will sum up to 10. When this is added to 10^7 the following will happen:

10,000,000 + 10 = 10,000,010

Since the floating-point values store seven digits of accuracy this number will remain!

supdun
  • 81
  • 2
  • So basically in the first method, it is like we are adding 1 but nothing is being added to 10,000,000? – abedzantout May 11 '15 at 13:45
  • What a computer does is that it saves after every operation, in this case being the first 7 bits. Since the value 1 we just added isn't among these first 7 bits, it doesn't get saved and the operation is lost. Basically it does get added but it just doesn't get stored. – supdun May 11 '15 at 13:47