Precise nth root
<p>I'm looking for Python Nth root function/algorithm but before you post: NO INTEGER ROOT, HELL!<br>
Where could I obtain at least a guide how to program <strong>Nth root function that produces precise <code>float</code>/<code>Decimal</code></strong>?<br>
Such function that <strong>doesn't return <code>1</code> nor <code>0</code> for <code>root(125, 1756482845)</code></strong> (1st argument is the number, 2nd is the root depth (or something)).</p>

<p><strong>EDIT:</strong> So, you were giving me this solution: <code>n ** (1.0 / exp)</code> which I knew when I asked this question, but it just doesn't work for, for example, <code>exp = 3</code>. You can't express <code>1/3</code> in terms of rational numbers, so <code>125 ** (1/3)</code> gives incorrect result <code>4.999999...</code>. I was asking for some "smart" algorithm, which gives correct result for such nice numbers and at least 4-decimal-points-accurate result for rational <code>exp</code>. If there isn't such function or algorithm, I will use this (<code>n ** (1/exp)</code>).</p>

<p>I would try the <a href="https://pypi.python.org/pypi/gmpy2" rel="nofollow">gmpy2</a> library.</p>

<pre><code>&gt;&gt;&gt; import gmpy2
&gt;&gt;&gt; gmpy2.root(125,3)
mpfr('5.0')
&gt;&gt;&gt; 
</code></pre>

<p><code>gmpy2</code> uses the <a href="http://www.mpfr.org/" rel="nofollow">MPFR</a> library to perform correctly rounded floating point operations. The default precision is 53 bits but that can be increased.</p>

<pre><code>&gt;&gt;&gt; gmpy2.root(1234567890123456789**11, 11)
mpfr('1.2345678901234568e+18')  # Last digits are incorrect.
&gt;&gt;&gt; gmpy2.get_context().precision=200
&gt;&gt;&gt; gmpy2.root(1234567890123456789**11, 11)
mpfr('1234567890123456789.0',200)
&gt;&gt;&gt; 
</code></pre>

<p>Disclaimer: I maintain <code>gmpy2</code>.</p>

python algorithm floating-point precision nth-root