// ************************************************************************** //
//                                                                            //
//    eses                   eses                                             //
//   eses                     eses                                            //
//  eses    eseses  esesese    eses   Embedded Systems Group                  //
//  ese    ese  ese ese         ese                                           //
//  ese    eseseses eseseses    ese   Department of Computer Science          //
//  eses   eses          ese   eses                                           //
//   eses   eseses  eseseses  eses    University of Kaiserslautern            //
//    eses                   eses                                             //
//                                                                            //
// ************************************************************************** //
// The function below computes the integer approximation to the square root
// of a given natural number a. It is known as Heron's algorithm, but is also
// derived by the Newton-Raphson iteration of f(x) = x^2-a to compute roots.
// ************************************************************************** //

function heron(nat a) : nat {
   nat xold,xnew;
   xnew = a;
   do {
      xold = xnew;
      xnew = (xold + a/xold)/2;
   } while(xnew < xold)
   return xold;
}

thread Heron {
   nat z;
   z = heron(121); // compute the square root of 121
}