I noticed this thread and couldn't help wondering why noone used the rather simple algorithm used below.
I program in C++Builder so you may need to adapt the code if you want to use it elsewhere. I have a form with an Edit box for input, a button to start the calculation and three labels to show the output.
Almost any positive number input gives a valid output.
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double a, b, c, d, e(0.0000000001), count(0);
a = atof(Edit1->Text.c_str());
if(a < 0)
{
Label1->Caption = "Domain error!";
return;
}
b = (1.0 + a)/2;
c = (b - a/b)/2;
d = fabs(c);
while(d > e && count < 1000)
{
b -= c;
c = (b - a/b)/2;
d = fabs(c);
++count;
}
Label1->Caption = AnsiString(b) + " by algorithm";
Label2->Caption = AnsiString(sqrt(a)) + " by sqrt() function";
Label3->Caption = AnsiString(count) + " itterations";
}
//---------------------------------------------------------------------------
You'll find the number of itterations is quite small and the comparison with sqrt() is very good. You could make e smaller to get a better result.
Please correct me if I am wrong.
I would like to hazard a guess. You could be using MS Visual C++. I believe that your codes rely on some other external files, such as Win API, dynamic link library files, etc., and you make use of them to effect GUI, like 3-d buttons, etc. without the need to code them. I know that even simple MS Foxprow executable program can not run without huge foxprow.esl library files, exceeding 1.2 MB.
What I have written was based on the context of a stand-alone C++ program compiled using non-commercial/ non-proprietary C++ compiler, such as CODE::BLOCK, Dev-C++, and Borland C++; and users can use the codes without other overheads, for which they have to pay a price. The executable C++ file can be very small, like 16K. I think users, perhaps including the OP, who use such compilers, -- which I use myself -- can not use your much simplified codes.
I think the freedom of choice of compilers is important. We need not be dependent on a proprietary C++. owned by a ruthless behemoth bent on monopolizing PC based software. We need to be able to breathe freely.
Regards,