// L-13 MCS 572 Wed 8 Feb 2012 : qd4sqrt2.cpp
// The code below illustrates the use of the QD library
// in a Newton iteration on x^2 - 2 = 0 to approximate sqrt(2)
// with 64 decimal places.

#include <iostream>
#include <iomanip>
#include <qd/qd_real.h>
using namespace std;

int main ( void )
{
   qd_real q("2");
   cout << setprecision(64) << q << endl;
   for(int i=0; i<8; i++)
   {
      qd_real dq = (q*q - 2.0)/(2.0*q);
      q = q - dq; cout << q << endl;
   }
   cout << scientific << setprecision(4);
   cout << "residual : " << q*q - 2.0 << endl;
   return 0;
}

