<div>1> 0.99999998 < 1.000000.   </div><div>true</div><div>2> 1.99999976 < 1.99999988.</div><div>true</div><div><br></div><div>What's the problem?</div><br><div class="gmail_quote">On Mon, May 14, 2012 at 9:41 AM, Angel J. Alvarez Miguel <span dir="ltr"><<a href="mailto:clist@uah.es" target="_blank">clist@uah.es</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div style="font-family:'Sans Serif';font-size:9pt;font-weight:400;font-style:normal">
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Hi guys</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">I need to compare two floats something like 0.99999998... vs 1.000000</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">and we came across accuracy problems when testing dihedral angles on a molecule...</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">so we read <a href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm" target="_blank">http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm</a></p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">and wanted to implement something like:</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#0000ff">if</span> (*(<span style="color:#0000ff">int</span>*)&f1 < *(<span style="color:#0000ff">int</span>*)&f2)...</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">when ef1 and f2 are floats... (f1 about 0.9999899.. and f2=1.0</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">is think we should start with...</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><<Padding:16,Myint:64>> = term_to_binary(1.9999976,[{minor_version,1}]).</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">and let Padding swallow the external format and tag while Myint gets the ieee754 float </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">But MyInt = 4611686017346523993 instead of <span style="font-family:'Courier New';font-size:10pt;vertical-align:bottom">1073741822</span></p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px;font-family:'Courier New';font-size:10pt;vertical-align:bottom"></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt;vertical-align:bottom">these conversion should follow ieee754 and being lexicografic ordered</span></p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt;vertical-align:bottom">but ...</span></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px;font-family:'Courier New';font-size:10pt;vertical-align:bottom"></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt;vertical-align:bottom">term_to_binary(1.99999976,[{minor_version,1}]).                  </span></p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt;vertical-align:bottom"><<131,70,63,255,255,255,191,147,83,89>></span></p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px;font-family:'Courier New';font-size:10pt;vertical-align:bottom"></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt;vertical-align:bottom">term_to_binary(1.99999988,[{minor_version,1}]).</span></p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt;vertical-align:bottom"><<131,70,63,255,255,255,223,201,169,173>> </span></p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px;font-family:'Courier New';font-size:10pt;vertical-align:bottom"></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt;vertical-align:bottom">doesnt seem to be the same thatn you spect to see after reading that page...</span></p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px;font-family:'Courier New';font-size:10pt;vertical-align:bottom"></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px;font-family:'Courier New';font-size:10pt;vertical-align:bottom"></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt;vertical-align:bottom">..What im doing wrong....?</span></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px;font-family:'Courier New';font-size:10pt;vertical-align:bottom"></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">ieee754 layout....</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<table border="0" style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px" cellspacing="2" cellpadding="0">
<tbody><tr>
<td width="155" style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">+1.99999976</span> </p></td>
<td width="108" style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">0x3FFFFFFE</span> </p></td>
<td width="106" style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p align="right" style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">1073741822</span> </p></td></tr>
<tr>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">+1.99999988</span> </p></td>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">0x3FFFFFFF</span> </p></td>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p align="right" style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">1073741823</span> </p></td></tr>
<tr>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">+2.00000000</span> </p></td>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">0x40000000</span> </p></td>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p align="right" style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">1073741824</span> </p></td></tr>
<tr>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">+2.00000024</span> </p></td>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">0x40000001</span> </p></td>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p align="right" style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">1073741825</span> </p></td></tr>
<tr>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">+2.00000048</span> </p></td>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">0x40000002</span> </p></td>
<td style="vertical-align:bottom;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0">
<p align="right" style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Courier New';font-size:10pt">1073741826</span></p></td></tr></tbody></table>
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px">Thanks!..</p><span class="HOEnZb"><font color="#888888">
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px"></p>
<p style="margin-top:12px;margin-bottom:12px;margin-left:0px;margin-right:0px;text-indent:0px">/Angel </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p></font></span></div><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Hynek Vychodil<br>Chief Scientists<br><br>GoodData<br>náměstí 28. října 1104/17, 602 00, Brno - Černá Pole<br>Office:   +420 530 50 7704<br>E-mail:  <a href="mailto:hynek@gooddata.com" target="_blank">hynek@gooddata.com</a><br>
Web:     <a href="http://www.gooddata.com" target="_blank">www.gooddata.com</a><br>