<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Adding floating-point numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291854#M60491</link>
    <description>&lt;P&gt;There is a thorough discussion on the topic in the SAS online docs called &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm" target="_blank"&gt;Numerical Accuracy in SAS Software.&lt;/A&gt; In my view a must-read for every SAS user.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Aug 2016 11:44:40 GMT</pubDate>
    <dc:creator>jklaverstijn</dc:creator>
    <dc:date>2016-08-16T11:44:40Z</dc:date>
    <item>
      <title>Adding floating-point numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291845#M60485</link>
      <description>&lt;P&gt;I am trying to understand how floating-point numbers are added in SAS. I have the following code:&lt;/P&gt;&lt;P&gt;data data1;&lt;BR /&gt;&amp;nbsp; format b c d binary64.;&lt;BR /&gt;&amp;nbsp; b=0.5; c=0.3; d=b+c;&lt;BR /&gt;&amp;nbsp; if d=0.8 then flag=1;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And flag is really set to 1.&lt;/P&gt;&lt;P&gt;In binary64:&lt;/P&gt;&lt;P&gt;b=0011111111100000000000000000000000000000000000000000000000000000&lt;/P&gt;&lt;P&gt;c=0011111111010011001100110011001100110011001100110011001100110011&lt;/P&gt;&lt;P&gt;d=0011111111101001100110011001100110011001100110011001100110011010&lt;/P&gt;&lt;P&gt;and 0.8 is represented the same as d. My problem is that when I try to add b and c, normalize the mantissas and add bit by bit I get a&amp;nbsp;number that differs from d. I checked all my calculations and this is not the case. Does anyone know why this can happen?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 10:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291845#M60485</guid>
      <dc:creator>Yuliia</dc:creator>
      <dc:date>2016-08-16T10:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Adding floating-point numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291848#M60486</link>
      <description>&lt;P&gt;You should use round() around calculated floating point. &amp;nbsp;There is a quirk in machines - can't remember the exact term, where a number can have a very small amount on the end of the number, e.g. 0.80000000000000001, but SAS does not display that. &amp;nbsp;If you apply the round() to this it will return exactly the number:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if round(d,.1)=0.8 then flag=1;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;you will see this a fair bit in proc sompare ouputs, where it shows differences in numbers which you cant see. &amp;nbsp;Just make sure to round your values to the correct decimal places.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 11:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291848#M60486</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-16T11:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Adding floating-point numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291854#M60491</link>
      <description>&lt;P&gt;There is a thorough discussion on the topic in the SAS online docs called &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm" target="_blank"&gt;Numerical Accuracy in SAS Software.&lt;/A&gt; In my view a must-read for every SAS user.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 11:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291854#M60491</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-08-16T11:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding floating-point numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291855#M60492</link>
      <description>Hi Jan, I've seen this and I am trying to repeat the process the same way in my understanding SAS would do it: i.e. adjust the mantissas, truncate afterwards but probably I am missing something as for this example I am not able to recreate the values. However if I take 0.7 and 0.1 and do the same I can recreate the values and see that 0.7+0.1 is not equal to 0.8</description>
      <pubDate>Tue, 16 Aug 2016 11:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291855#M60492</guid>
      <dc:creator>Yuliia</dc:creator>
      <dc:date>2016-08-16T11:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding floating-point numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291857#M60493</link>
      <description>&lt;P&gt;Thanks for the tip. When I perform the comparison 0.5+0.3 does equal 0.8, however when I actually try to repeat what SAS does in the way I understand it I can't. I get a different value, not 0011111111101001100110011001100110011001100110011001100110011010&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 11:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291857#M60493</guid>
      <dc:creator>Yuliia</dc:creator>
      <dc:date>2016-08-16T11:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Adding floating-point numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291868#M60496</link>
      <description>&lt;P&gt;Keep in mind that 52 bits are stored, but the precision is actually 53 bits (there's always a "hidden" 1 at the beginning of the mantissa) and the math unit in the CPU can probably use all it's 64 integer bits for adding.&lt;/P&gt;
&lt;P&gt;So your CPU adds&lt;/P&gt;
&lt;PRE&gt;10000000000000000000000000000000000000000000000000000&lt;BR /&gt;+
010011001100110011001100110011001100110011001100110011
=
110011001100110011001100110011001100110011001100110011&lt;/PRE&gt;
&lt;P&gt;Before you store that back, the leading 1 is eliminated, the exponent once again set to -1, and the 53rd bit from the remaining number is rounded to the 52nd, which is also 1, so the 51st is set to 1 and the 52nd to 0.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 12:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291868#M60496</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-16T12:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Adding floating-point numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291873#M60498</link>
      <description>&lt;P&gt;Thanks so much! I forgot about the rounding. Now everything is pretty clear.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 12:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-floating-point-numbers/m-p/291873#M60498</guid>
      <dc:creator>Yuliia</dc:creator>
      <dc:date>2016-08-16T12:45:17Z</dc:date>
    </item>
  </channel>
</rss>

