title: higher precision in python
body: <p>I am running some <code>python</code> v3.3.2 scripts that use <code>numpy</code> and <code>scipy</code> and <code>math</code>. I am suspecting that there is an issue of numerical precision in my computation, and I would like to increase the precision in some particular modules that I have written and see if it makes a difference in the final result. In my module I am using some algebraic manipulations and <code>numpy.sqrt</code>.</p>
  
  <p>How do I manipulate the precision of the computations in a module that is already written by me?(I can modify it). I have seen that there are several modules available like <code>decimal</code> and <code>mpmath</code> and <code>bigfloat</code>, and I was trying to figure out from the documentation which one would be more suitable for my task. The first one is already installed and I should install the other two. Ideally I would like to write a command on the top of the module and specifying the precision that I need in that module, does something like that exist?</p>
  
  <p>EDIT ---------</p>
  
  <p>I think the problem may come from computation of second derivative:</p>
  
  <pre><code>def secondderivative(x,y):
    xl     = np.roll(x,1) # x1
    xr     = np.roll(x,-1)# x3
    yl     = np.roll(y,1)
    yr     = np.roll(y,-1)
  
    ind    = np.where(np.isnan(y) | np.isnan(yl) | np.isnan(yr) )[0]
  
    deriv2 = (2 * yl / ((x - xl)  * (xr - xl))
          - 2 * y  / ((xr - x)  * (x - xl))
          + 2 * yr / ((xr - xl) * (xr - x)))
  
    for i in ind:
      deriv2[i] = np.nan
  
    deriv2[0]             = np.nan
    deriv2[len(deriv2)-1] = np.nan
    return deriv2
  </code></pre>
  
  <p>I have seen the result from gradient is completely different:</p>
  
  <pre><code>np.gradient(np.gradient(y,x),x)
  </code></pre>