RosettaCodeData/Task/Arithmetic-geometric-mean/Factor/arithmetic-geometric-mean.factor

7 lines
200 B
Factor
Raw Permalink Normal View History

2018-06-22 20:57:24 +00:00
USING: kernel math math.functions prettyprint ;
IN: rosetta-code.arithmetic-geometric-mean
: agm ( a g -- a' g' ) 2dup [ + 0.5 * ] 2dip * sqrt ;
1 1 2 sqrt / [ 2dup - 1e-15 > ] [ agm ] while drop .