C: How to perform accurate floating-point operations? : <p>I am well aware that <code>0.1+0.2 != 0.3</code> because of precision errors. However I need it to be equal to 0.3.</p>

<p>My solution would be to :</p>

<ul>
<li>Declare an <code>add</code> function that returns the correct <code>double</code>.</li>
<li>Inside this function, add the two numbers then round to the 13th digit.</li>
</ul>

<p>This would work for 0.49999999999999994 and 0.30000000000000004.</p>

<p>How would I implement such a rounding function? Is there another way?</p>
