PureBytes Links
Trading Reference Links
|
Method 1 needs 30,629 iterations to calculate the SQRT(1000).
Method 2 needs only 313 for the same accuracy.
In this case a longer code [Method 2] is much faster.
Verify in your Indicator Builder.
NUM=1000;
//Method 1
DEC=3;It=0;Y=0;I=1;STEP=10^(-DEC);
while(I^2<NUM)
{
Y=I;
I=I+STEP;
It=It+1;
}
Title="SQRT("+WriteVal(NUM,1.0)+")="+WriteVal(Y,1+0.1*DEC)+" [Method
1 : "+WriteVal(It,1.0)+" iterations]";
//Method 2
DEC0=1;It0=0;Y0=0;I=1;STEP0=10^(-DEC0);
while(I^2<NUM)
{
Y0=I;
I=I+STEP0;
It0=It0+1;
DEC1=DEC0+1;
}
Title=Title+"\n\nSQRT("+WriteVal(NUM,1.0)+")="+WriteVal(Y0,1+0.1*DEC0)
+" ["+WriteVal(It0,1.0)+" iterations]";
I=Y0;STEP1=10^(-DEC1);It1=0;Y1=0;
while(I^2<NUM)
{
Y1=I;
I=I+STEP1;
It1=It1+1;
DEC2=DEC1+1;
}
Title=Title+"\nSQRT("+WriteVal(NUM,1.0)+")="+WriteVal(Y1,1+0.1*DEC1)
+" ["+WriteVal(It1,1.0)+" iterations]";
I=Y1;STEP2=10^(-DEC2);It2=0;Y2=0;
while(I^2<NUM)
{
Y2=I;
I=I+STEP2;
It2=It2+1;
DEC3=DEC2+1;
}
Title=Title+"\nSQRT("+WriteVal(NUM,1.0)+")="+WriteVal(Y2,1+0.1*DEC2)
+" ["+WriteVal(It2,1.0)+" iterations]";
Title=Title+"\n\nSQRT("+WriteVal(NUM,1.0)+")="+WriteVal(Y2,1+0.1*DEC2)
+" [Method2 : "+WriteVal(It0+It1+It2,1.0)+" iterations]";
Dimitris
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~->
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|