How to find square root with 20 digit precision in C++?
<p>Hi guys I'm stuck with this homework where I need to find the root of equation using <strong>Bisection method</strong> with precision 10^-20 aka 0.00000000000000000001 so at first I though it was cause I wasn't using long double  and also L at the end of the numbers, however even when I use it my last 3 digits are not correct, for the code that is given below ask you to give the number for a in my case is 5 , so I get 2.3227751229355622087</p>

<p>while the correct answer should be 2.3227751229355622988, I really can't find my mistake , will be happy if some1 assist me with this problem.  </p>

<p><strong>For your reference, here's a description and illustration of the <a href="http://www.mathpath.org/Algor/squareroot/algor.square.root.binary.htm" rel="nofollow noreferrer">Bisection method</a></strong>.  </p>

<p>Here's my code:</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;cmath&gt;
#include&lt;math.h&gt;
#include&lt;iomanip&gt;

using namespace std;

long double f(long double   x, long double a);
long double F = 123456L % 100L;

long double f(long double  x, long double a)
{
    long double  sum = pow(x, 5) - a*x - F;
    return sum;
}

int main()
{
    cout.setf(ios::fixed);
    long double a, b, c, fa, fb, fc;
    long double e;
    long double aa;
    bool flag = true;
    while (cin &gt;&gt; aa)
    {
        cout.precision(19);
        flag = true;
        a = 0L;
        b = 10L;
        e = 0.00000000000000000001L;

        if (f(a, aa)*f(b, aa)&gt;0)
        {
            flag = false;
        }

        while(fabs(a-b)&gt;=e){
            c = (a + b) / 2.0L;
            fa = f(a, aa);
            fb = f(b, aa);
            fc = f(c, aa);

            if (fc == 0)
            {       
                break;
            }

            if (fa*fc&gt;0)
            {
                a = c;
            }
            else if (fa*fc&lt;0)
            {
                b = c;
            }
        } 

        if (flag == true)
        {
            cout  &lt;&lt; c &lt;&lt; endl;
        }
        else 
        {
            cout &lt;&lt; "NO SOLUTION" &lt;&lt; endl;
        }
    }
    return 0;
 }
</code></pre>