title: How can I check if std::pow will overflow double
body: <p>I have a function that deals with arbitrarily large grids. I need to compute if a grid to the power of another number will fit into a double due to using <code>std::pow</code>. If it cannot, I want to take a different branch and use gnu multiprecision library instead of normal. </p>
  
  <p>Is there a quick way to see if:</p>
  
  <pre><code>int a = 1024;
  int b = 0-10;
  
  if(checkPowFitsDouble(a, b)) {
      long c = static_cast&lt;long&gt;(std::pow(a, b)); //this will only work if b &lt; 6
  } else {
      mpz_t c; //yada yada gmp
  }
  </code></pre>
  
  <p>I am completely stumped on checkPowFitsDouble; perhaps there is some math trick I don't know  of.</p>