  uses console

  -----------------------------
  macro approx(fun, est1, est2)
  =============================
  '
  double ans1,ans2,scale
  'est1               'first estimate of answer
  'est2               'second estimate of answer
  ans1=fun(est1) 'error from first estimate
  ans2=fun(est2) 'error from second estimate
  if ans1<>ans2
    scale=(est2-est1)/(ans2-ans1)
    est1=est2
    est2-=ans2*scale
  endif 
  end macro

  double e1,e2
  '
  e1=10
  e2=20
  function fn(double a) as double
    'null expressions:
    '
    'return a*a-2       'square root of 2
    'return (1/(a*a))-2 'inverse square root of 2
    'return (1/a)-a-1   'little phi
    'return (1/a)-a+1   'big phi
    'return pow(2,a)-1/3   'log2 n
    return exp(a)-1000   'lin n
  end function
  '
  int i
  for i=1 to 20
    double e3=e2
    approx(fn,e1,e2)
    if e3=e2
      exit for
    endif
    print e2 cr 
  next
  wait

