UNB/ CS/ David Bremner/ teaching/ java/ MathAlgs.java
/**
   A class for mathematical algorithms.
*/

public class MathAlgs
{  /**
      Computes the square root, using Heron's algorithm.
      @param a a floating-point number
      @return the square root of a, or 0 if a is negative
   */      
   public static double sqrt(double a)
   {  if (a <= 0) return 0;
      double xnew = a;
      double xold;
      do
      {  xold = xnew;
         xnew = (xold + a / xold) / 2;
      } while (!Numeric.approxEqual(xnew, xold));
      return xnew;
   }      
}