code: public static double pow2(double x)
      {
          if(x > Double.MAX_EXPONENT)
              return Double.POSITIVE_INFINITY;
          else if(x < Double.MIN_EXPONENT)
              return 0;
          else if(x < 0)
              return 1.0/pow2(-x);
          //x is positive at this point
  
          double floorXd = Math.floor(x);
          int floorX = (int) floorXd;
          double frac = x-floorXd;
          
          double pow2frac = -4.704682932438695+27.543765058113320/(4.828085122666891-frac)-0.490129071734273 * frac;
          
          return pow2frac*longBitsToDouble((floorX+1023L)<<52);
      }
docs: Computes 2<sup>x</sup>.<br>
  The results are generally accurate to an relative error of
  10<sup>-4</sup>, but can be as accurate as 10<sup>-10</sup>
  
  @param x the power to raise to
  @return