<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:12pt;font-family:Sans Serif">
<p>Aditya Siram wrote:</p>
<p>&gt; Prelude&gt; sin pi</p>
<p>&gt; 1.22460635382238e-16  --WRONG!</p>
<p></p>
<p>Neil Mitchell wrote:</p>
<p>&gt; Floating point numbers are not exact, the value of pi is not exact</p>
<p>&gt; either, and I guess that between them they are giving you errors.</p>
<p></p>
<p>Yes. Actually, this particular inexactness is entirely due to the value of pi. The calculation of sin pi is being performed using the Double data type, which cannot represent pi exactly. Since Double uses binary fractions, doing</p>
<p>   Hugs.Base&gt; pi</p>
<p>   3.14159265358979</p>
<p>shows a decimal approximation to the binary approximation.  To investigate the representation  of pi, subtract from it a number which _can_ be represented easily and exactly as a binary fraction, as follows:</p>
<p>   Hugs.Base&gt; pi-3.140625</p>
<p>   0.000967653589793116</p>
<p>This shows that pi is represented using an approximation that is close to</p>
<p>   3.141592653589793116</p>
<p>This value, the computer's pi, differs from true pi by</p>
<p>   0.000000000000000122...</p>
<p>so the sin function is working perfectly.</p>
<p></p>
</body></html>