Subj : Re: sqrt algo To : comp.programming From : Sc0rpi0 Date : Fri Jul 15 2005 11:58 pm CBFalconer: >>>> Here is an iterative one (from the ancient Egypt, I have been told): >>>> >>>> current_estimate = 0.5*(previous_estimate + number/previous_estimate) >>>> >>>> You'll have to terminate it when you are "close enough". (It >>>> converges quite quickly, the number itself may serve as the first >>>> estimate.) >>> >>> In which case you might as well take 1. >> >> I suspect you've misunderstood the relative precedence of + and / >> in the above formula. :) > > I don't think so. You can plug either 'number' or '1' as > 'previous_estimate' into the above formula, and you will get the > same result for 'current_estimate'. Not always same... first_est=1 is better cause number can be 0 in sqrt() in this case ;P first_est=1 cur_est=0.5*(1+0/1) first_est=number: cur_est=0.5*(0+0/0 ?) -- Sc0rpi0 I hated going to weddings. All the grandmas would poke me saying "You're next". They stopped that when I started doing it to them at funerals. .