title: Precision issue of integrate function in R
body: <p>When using the <code>integrate()</code> function in R, some precision issues make me confused. For example, I want to integrate this function:</p>
  
  <pre><code>p &lt;- function(x)exp(-x^2)
  </code></pre>
  
  <p>I choose the interval [-1e3,1e3], and it gives the right answer:</p>
  
  <pre><code>&gt; integrate(p, -1e3, 1e3)
  1.772454 with absolute error &lt; 7.8e-09
  </code></pre>
  
  <p>But if I expand the interval to [-1e9,1e9], it's wrong:</p>
  
  <pre><code>&gt; integrate(p, -1e9, 1e9)
  0 with absolute error &lt; 0
  </code></pre>
  
  <p>In order not to tune the interval, I try to use <code>Inf</code>:</p>
  
  <pre><code>&gt; integrate(p, -Inf, Inf)
  1.772454 with absolute error &lt; 4.3e-06
  </code></pre>
  
  <p>It works, but soon I find there are some other problems :</p>
  
  <pre><code>&gt; integrate(p, -Inf, -Inf)
  1.772454 with absolute error &lt; 4.3e-06
  </code></pre>
  
  <p>In this case it can't give the right answer 0.</p>
  
  <p>I wonder why these precision problem will happen and are there any methods to avoid such problem?</p>