title: Pow function in C is outputting zero
body: <p>I'm writing an integration script, and it uses a non-uniform grid. I'm using the pow function in math.h to calculate by what each value of x should be multiplied to get to the next value of x (this value is xmult in my code). However, for some reason, my pow function outputs zero, even though my calculator says that it should not be. Here are the relevant snippets from my code:</p>
  <pre><code>#include &quot;stdio.h&quot;
  #include &quot;math.h&quot;
  ...
  int N = 10240;
  double recN = 1/N;
  double upperlim = 4;
  double lowerlim = 0.0001;
  double limratio = upperlim/lowerlim;
  double xmult;
  xmult = pow(limratio,recN);
  printf(&quot;%e\n&quot;,xmult);
  </code></pre>
  <p>The output of that printf function is 1.000000e+00 even though my calculated value does not round to that. I am compiling using gcc on CentOS with the -lm flag, it does not compile without that flag set. If it is any more help, the full code is below (the final output of the program being 0.000000e+00).</p>
  <pre><code>#include &quot;stdio.h&quot;
  #include &quot;math.h&quot;
  
  int main() {
    int N = 10240;
    double recN = 1/N;
    double pi = M_PI;
    double upperlim = 4;
    double lowerlim = 0.0001;
    double limratio = upperlim/lowerlim;
    double h;
    double f;
    double fnext;
    double ftot = 0;
    double ftot2 = 0;
    double x=lowerlim;
    double xmult;
    double xnext;
    int i;
    double func(double x){
      return sin(x) * exp(-x);
      }
    fnext = func(lowerlim);
    xmult = pow(limratio,recN);
    printf(&quot;%e\n&quot;,xmult);
    for (i=0;i&lt;N;i++){
      f = fnext;
      fnext = func(x*xmult);
      xnext = x * xmult;
      h = xnext - x;
      ftot = 0.5*h*(f+fnext);
      ftot2 = ftot2  + ftot;
      x = xnext;
    }
    printf(&quot;%e\n&quot;,ftot2);
   }
  </code></pre>