title: Writing a Power method with a minimum amount of steps n(log)N
body: <p>I'm trying to write the Power method and now the question is how to write it in a better way. Here is my code, I've verified it works well for all the Power conditions, however I can't think on a better solution.</p>
  
  <p>The real issue is how I express the power with a Negative exponent in <code>O(log)n</code> condition</p>
  
  <pre><code>public static double raiseToPowerIterative(double x, int n) {
      double sol = 1;
      if (n == 0) {
          return 1;
      }
      if (n &gt; 0) {
          for (int i = 1; i &lt;= n;i++) {
              sol *= x;
          }
          return sol;
      } else if (n &lt; 0){
          for (int i = -1; i &gt;= n; i--) {
              sol /= x;
          }
      }
      return sol;
  }
  </code></pre>