Author: | idiot |
---|---|
Mode: | factor |
Date: | Wed, 21 Oct 2009 07:48:57 |
: average ( x y -- x ) + 2 / ; : square ( x -- x ) dup * ; : good-enough? ( guess x -- tf ) swap square - abs 0.001 < ; : improve ( guess x -- improved ) over / average ; : sqrt-iter ( guess x -- x ) 2dup good-enough? [ drop ] [ 2dup improve [ drop ] 2dip swap sqrt-iter ] if ; : mysqrt ( x -- x ) 1.0 swap sqrt-iter ;