Calculating a Sum in C: Finding the Error in Floating Point Precision?

  • MHB
  • Thread starter mathmari
  • Start date
  • Tags
    Sum
In summary: Suppose you add a small value $\delta$ to x.If x has a significant digits of 7, then the first 7 digits of $\delta$ will get lost.If you add a small value $\delta$ to x, then the first $n$ digits of $\delta$ will get lost, where $n$ is the number of significant digits of x.Given two integers a and b, return the result of a / b in float.In summary, this program calculates the division of two integers and returns the result as a float.
  • #36
mathmari said:
If you multiply your result with 6 and find the square root and then the error,how could we explain why the forward method gives better results for smaller n??

Lucky bad rounding.

Suppose we do the calculation with 2 significant decimal digits for n=4.
Then we get:
forward: ((1+0.25)+0.11)+0.063 = 1.5
backward: 1+(0.25+(0.11+0.063)) = 1.4

As you can see, the forward result is closer to $\pi^2/6 \approx 1.64$.
That is because of the lucky bad rounding of 0.25 to 0.3 and of 0.063 to 0.1.

Note that after iteration n=4, the forward result does not increase anymore (the next term is 0.04). But the backward result keeps getting closer to the desired end result.
 
Mathematics news on Phys.org
  • #37
Thank you very very much! ;) :D
 

Similar threads

Replies
31
Views
2K
Replies
7
Views
2K
Replies
8
Views
1K
Replies
22
Views
3K
Replies
2
Views
1K
Replies
20
Views
2K
Replies
6
Views
2K
Replies
2
Views
2K
Back
Top