/**
 * Raise a double to a positive integer power.
 * Fast version of Math.pow.
 * @param x number to be taken to a power.
 * @param n power to take x to. 0 <= n <= Integer.MAX_VALUE
 * Negative numbers will be treated as unsigned positives.
 * @return x to the power n
 * @author Patricia Shanahan pats@acm.org
 */
public static double power( double x , int n )
   {
   int bitMask = n;
   double evenPower = x;
   double result;
   if ( (bitMask & 1) != 0 )
      {
      result = x;
      }
   else
      {
      result = 1;
      }
   bitMask >>>= 1;
   while ( bitMask != 0 )
      {
      evenPower *= evenPower;
      if ( (bitMask & 1) != 0 )
         {
         result *= evenPower;
         }
      bitMask >>>= 1;
      } // end while
   return result;
   } // end power