Getting 'large' errors that seem too big to be from rounding alone
<p>When I use Python, I'm getting some significant rounding errors that seem too large for simply floating point problems. I have the following variables:</p>

<pre><code>p = 2.2*10**9
m = 0.510999*10**6
</code></pre>

<p>I then send it through the following:</p>

<pre><code>b = 1/np.sqrt((m/p)**2 + 1) = 0.99999997302479693
</code></pre>

<p>I then use this value through another equation that should return p:</p>

<pre><code>p = (1/np.sqrt(1-b**2)) * m * b = 2200000008.1937...
</code></pre>

<p>Aforementioned gives a difference in p of 8.19... (error in the 9th decimal place if scientific notation is used), which seems to be way too big to be simply a matter of rounding.</p>

<p>I've tried using <code>Decimal().sqrt()</code> with arbitrarily high precision for all the calculations and I get a difference in p of 1.8935..., which is only marginally better.</p>

<p>Is there a better way of getting higher precision?</p>

<p>It is the operation</p>

<pre><code>sqrt(1+x)
</code></pre>

<p>that loses you that much precision. Or really the <code>1+x</code> part of it. As your <code>x=(m/p)**2</code> has the magnitude <code>1e-6</code>, you lose about 5-6 digits of the 15-16 valid decimal digits of <code>x</code>, so that only 9-10 valid digits remain. And in the reconstruction you see exactly that, (only) the leading 9 digits are correct.</p>

python python-3.x numpy math rounding