<?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: INT function returning unexpected results in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954979#M372967</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Using formats, we can see that 1117.11*100 is an irrational number in binary:&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;(...)&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col" width="52.0938px" height="19px"&gt;Variable&lt;/TH&gt;
&lt;TH class="r b header" scope="col" width="68.6094px" height="19px"&gt;Value&lt;/TH&gt;
&lt;TH class="r b header" scope="col" width="625.5px" height="19px"&gt;Result&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="52.0938px" height="32px" class="l data"&gt;&lt;FONT face="courier new,courier"&gt;y&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="68.6094px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;111711&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="625.5px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;0100000011111011010001011110&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;111111111111111111111111111111111111&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like using the BINARY64. format in such situations. But I wouldn't call that number "irrational" because in mathematics this term has a special meaning (i.e., not being the ratio of two integers; cf. Wikipedia article&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Irrational_number" target="_blank" rel="noopener"&gt;Irrational number&lt;/A&gt;) which doesn't apply here. It's not even a repeating fraction (like 1/3=0.33333... in the decimal system), although the long string of 1s resembles 1/9=0.11111... in the decimal system. Since 64-bit floating-point numbers have only a finite number of binary digits (not more than 64 obviously) they are always rational.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The long string of 1s above is just the result of a rounding error: The decimal number 1117.11 written (mathematically) in the binary system &lt;EM&gt;is&lt;/EM&gt; a (rational) repeating fraction:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;&lt;FONT color="#00DD00"&gt;1&lt;/FONT&gt;&lt;FONT color="#FF00FF"&gt;0001011101&lt;/FONT&gt;.00&lt;FONT color="#00CCFF"&gt;01110000101000111101&lt;/FONT&gt;0111000010100011110101110000101000111101...&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;The 20-digit-pattern highlighted in blue is actually repeated forever (only three blocks of these are shown above). However, in the BINARY64. representation of that number (shown below) the infinite sequence is &lt;EM&gt;rounded&lt;/EM&gt; to fit into the 64 bits, more precisely: into the 52 &lt;EM&gt;mantissa&lt;/EM&gt; bits plus the implied bit (highlighted in green above).&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;010000001001&lt;FONT color="#FF00FF"&gt;0001011101&lt;/FONT&gt;00&lt;FONT color="#00CCFF"&gt;01110000101000111101&lt;/FONT&gt;01110000101000111101&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Due to the space restriction in the mantissa, the 20-digit-pattern is repeated only once, the next block "&lt;FONT face="courier new,courier"&gt;011100&lt;/FONT&gt;..." is rounded off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Multiplying this number by the decimal number 100 (binary: 1100100) amounts to summing three shifted copies of it (because of the three 1s in "1100100").&lt;/P&gt;
&lt;P&gt;Written mathematically as multiples of 2**10=1024:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt; 1000101.1101000111000010100011110101110000101000111101    
+ 100010.11101000111000010100011110101110000101000111101   
+    100.01011101000111000010100011110101110000101000111101
-----------------------------------------------------------
 &lt;STRONG&gt;1101101.0001011110111111111111111111111111111111111111&lt;/STRONG&gt;0101&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Now we see how the round-off error mentioned above affects the summation and leads to a result that is slightly too small. Moreover, it contains 57 binary digits, so it must be rounded again to 52+1=53 bits: The "&lt;FONT face="courier new,courier"&gt;0101&lt;/FONT&gt;" at the end is rounded down (because of the leading zero), leaving that long (but not infinite) string of 1s in the mantissa.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/369711"&gt;@cklager44&lt;/a&gt;: "&lt;SPAN&gt;If the argument is within 1E-12 of an integer, the INT function fuzzes the result to be equal to that integer." (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1b1zd0wuyufp0n1jbqlr27p4eay.htm" target="_blank" rel="noopener"&gt;INT function documentation&lt;/A&gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Unfortunately, the difference between the result and the exact integer 111711 exceeds 1E-12, as Tom has shown already (&lt;FONT face="courier new,courier"&gt;diff=1.4551&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;E-11&lt;/FONT&gt;).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The situation with 1117.01*100 is actually similar, &lt;EM&gt;but&lt;/EM&gt; in the last rounding step -- from 57 to 53 bits -- we are just lucky: Instead of "&lt;FONT face="courier new,courier"&gt;0101&lt;/FONT&gt;" (as above from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;1117.11*100&lt;/FONT&gt;) a "&lt;FONT face="courier new,courier"&gt;1111&lt;/FONT&gt;" needs to be rounded and this is rounded &lt;STRONG&gt;&lt;EM&gt;up&lt;/EM&gt;&lt;/STRONG&gt; (because of the leading 1), which compensates the previous rounding error and leads to the proper internal binary representation of the integer 111701.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jan 2025 23:32:40 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2025-01-02T23:32:40Z</dc:date>
    <item>
      <title>INT function returning unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954954#M372957</link>
      <description>&lt;P&gt;data testint;&lt;/P&gt;&lt;P&gt;x=1117.11;&lt;/P&gt;&lt;P&gt;y=x*100;&lt;/P&gt;&lt;P&gt;z=int(x*100);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would expect y and z to be the same, but they are not. I get 111711 and 111710 respectively.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is INT doing something wrong, or am I doing something wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I change x from 1117.11 to 1117.01, it works as I would expect it to work - y and z are both 111701.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 20:41:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954954#M372957</guid>
      <dc:creator>cklager44</dc:creator>
      <dc:date>2025-01-02T20:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: INT function returning unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954959#M372960</link>
      <description>&lt;P&gt;Welcome to the world of BASE 2 numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some decimal fractions cannot be represented exactly as base 2 fractions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;11/100ths cannot be represented exactly in BASE 2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Because of the impossibility of storing the 11/100ths exactly in a finite number of binary digits &amp;nbsp;1,117.11 times 100 is not exactly equal 111,711 .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      x=1117.11;
3      y=x*100;
4      diff = 111711-y;
5      put x= / y= / diff=best32. ;
6    run;

x=1117.11
y=111711
diff=1.4551915228366E-11
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 21:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954959#M372960</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-02T21:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: INT function returning unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954960#M372961</link>
      <description>&lt;P&gt;Ok, but INT fuzzes the results to take that into account. INTZ does not, so I wouldn't be entirely surprised to see INTZ return the occasional weird answer. But not INT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 21:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954960#M372961</guid>
      <dc:creator>cklager44</dc:creator>
      <dc:date>2025-01-02T21:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: INT function returning unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954961#M372962</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/369711"&gt;@cklager44&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ok, but INT fuzzes the results to take that into account. INTZ does not, so I wouldn't be entirely surprised to see INTZ return the occasional weird answer. But not INT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What FUZZ does it use?&amp;nbsp; Best to add your own ROUND() to whatever level of precision you need.&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      x0=1117.11;
3      y0=111711;
4      z1=x0*100;
5      z2=int(x0*100);
6      z3=int(round(x0*100,1e-10));
7      d1 = y0-z1;
8      d2 = y0-z2;
9      d3 = y0-z3;
10     put (_all_) (/=best32.);
11     put (_all_) (/=hex16.);
12   run;


x0=1117.11
y0=111711
z1=111711
z2=111710
z3=111711
d1=1.4551915228366E-11
d2=1
d3=0

x0=40917470A3D70A3D
y0=40FB45F000000000
z1=40FB45EFFFFFFFFF
z2=40FB45E000000000
z3=40FB45F000000000
d1=3DB0000000000000
d2=3FF0000000000000
d3=0000000000000000
&lt;/PRE&gt;
&lt;P&gt;The difference appears be about one bit.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;y0=40FB45F000000000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;z1=40FB45EFFFFFFFFF&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 21:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954961#M372962</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-02T21:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: INT function returning unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954963#M372964</link>
      <description>&lt;P&gt;Using formats, we can see that 1117.11*100 is an irrational number in binary:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   x=1117.11;
   y=x*100;
   z1=int(x*100);
   z2=int(y);
run;

proc sql;
select x  format=binary64.
      ,y  format=binary64.
      ,z1 format=binary64.
      ,z2 format=binary64.
   from test
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col" width="52.0938px" height="19px"&gt;Variable&lt;/TH&gt;
&lt;TH class="r b header" scope="col" width="68.6094px" height="19px"&gt;Value&lt;/TH&gt;
&lt;TH class="r b header" scope="col" width="625.5px" height="19px"&gt;Result&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="52.0938px" height="32px" class="l data"&gt;&lt;FONT face="courier new,courier"&gt;y&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="68.6094px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;111711&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="625.5px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;0100000011111011010001011110&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;111111111111111111111111111111111111&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="52.0938px" height="32px" class="l data"&gt;&lt;FONT face="courier new,courier"&gt;z1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="68.6094px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;111710&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="625.5px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;0100000011111011010001011110000000000000000000000000000000000000&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="52.0938px" height="32px" class="l data"&gt;&lt;FONT face="courier new,courier"&gt;z2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="68.6094px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;111710&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="625.5px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;0100000011111011010001011110000000000000000000000000000000000000&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;In all cases the ROUND function truncates the repeating&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#000000"&gt; giving consistent, repeatable results. Check out the SAS Docs section titled "&lt;A href="http://the&amp;nbsp;https://go.documentation.sas.com/doc/en/lrcon/9.4/p0ji1unv6thm0dn1gp4t01a1u0g6.htm#p06gsu0m578tazn1gw2x9trob69" target="_self"&gt;Troubleshooting Errors in Precision&lt;/A&gt;", under the main topic&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/lrcon/9.4/p0ji1unv6thm0dn1gp4t01a1u0g6.htm" target="_self"&gt;Numerical Accuracy in SAS Software.&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 02 Jan 2025 21:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954963#M372964</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2025-01-02T21:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: INT function returning unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954979#M372967</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Using formats, we can see that 1117.11*100 is an irrational number in binary:&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;(...)&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col" width="52.0938px" height="19px"&gt;Variable&lt;/TH&gt;
&lt;TH class="r b header" scope="col" width="68.6094px" height="19px"&gt;Value&lt;/TH&gt;
&lt;TH class="r b header" scope="col" width="625.5px" height="19px"&gt;Result&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="52.0938px" height="32px" class="l data"&gt;&lt;FONT face="courier new,courier"&gt;y&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="68.6094px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;111711&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="625.5px" height="32px" class="r data"&gt;&lt;FONT face="courier new,courier"&gt;0100000011111011010001011110&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;111111111111111111111111111111111111&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like using the BINARY64. format in such situations. But I wouldn't call that number "irrational" because in mathematics this term has a special meaning (i.e., not being the ratio of two integers; cf. Wikipedia article&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Irrational_number" target="_blank" rel="noopener"&gt;Irrational number&lt;/A&gt;) which doesn't apply here. It's not even a repeating fraction (like 1/3=0.33333... in the decimal system), although the long string of 1s resembles 1/9=0.11111... in the decimal system. Since 64-bit floating-point numbers have only a finite number of binary digits (not more than 64 obviously) they are always rational.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The long string of 1s above is just the result of a rounding error: The decimal number 1117.11 written (mathematically) in the binary system &lt;EM&gt;is&lt;/EM&gt; a (rational) repeating fraction:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;&lt;FONT color="#00DD00"&gt;1&lt;/FONT&gt;&lt;FONT color="#FF00FF"&gt;0001011101&lt;/FONT&gt;.00&lt;FONT color="#00CCFF"&gt;01110000101000111101&lt;/FONT&gt;0111000010100011110101110000101000111101...&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;The 20-digit-pattern highlighted in blue is actually repeated forever (only three blocks of these are shown above). However, in the BINARY64. representation of that number (shown below) the infinite sequence is &lt;EM&gt;rounded&lt;/EM&gt; to fit into the 64 bits, more precisely: into the 52 &lt;EM&gt;mantissa&lt;/EM&gt; bits plus the implied bit (highlighted in green above).&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;010000001001&lt;FONT color="#FF00FF"&gt;0001011101&lt;/FONT&gt;00&lt;FONT color="#00CCFF"&gt;01110000101000111101&lt;/FONT&gt;01110000101000111101&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Due to the space restriction in the mantissa, the 20-digit-pattern is repeated only once, the next block "&lt;FONT face="courier new,courier"&gt;011100&lt;/FONT&gt;..." is rounded off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Multiplying this number by the decimal number 100 (binary: 1100100) amounts to summing three shifted copies of it (because of the three 1s in "1100100").&lt;/P&gt;
&lt;P&gt;Written mathematically as multiples of 2**10=1024:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt; 1000101.1101000111000010100011110101110000101000111101    
+ 100010.11101000111000010100011110101110000101000111101   
+    100.01011101000111000010100011110101110000101000111101
-----------------------------------------------------------
 &lt;STRONG&gt;1101101.0001011110111111111111111111111111111111111111&lt;/STRONG&gt;0101&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Now we see how the round-off error mentioned above affects the summation and leads to a result that is slightly too small. Moreover, it contains 57 binary digits, so it must be rounded again to 52+1=53 bits: The "&lt;FONT face="courier new,courier"&gt;0101&lt;/FONT&gt;" at the end is rounded down (because of the leading zero), leaving that long (but not infinite) string of 1s in the mantissa.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/369711"&gt;@cklager44&lt;/a&gt;: "&lt;SPAN&gt;If the argument is within 1E-12 of an integer, the INT function fuzzes the result to be equal to that integer." (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1b1zd0wuyufp0n1jbqlr27p4eay.htm" target="_blank" rel="noopener"&gt;INT function documentation&lt;/A&gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Unfortunately, the difference between the result and the exact integer 111711 exceeds 1E-12, as Tom has shown already (&lt;FONT face="courier new,courier"&gt;diff=1.4551&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;E-11&lt;/FONT&gt;).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The situation with 1117.01*100 is actually similar, &lt;EM&gt;but&lt;/EM&gt; in the last rounding step -- from 57 to 53 bits -- we are just lucky: Instead of "&lt;FONT face="courier new,courier"&gt;0101&lt;/FONT&gt;" (as above from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;1117.11*100&lt;/FONT&gt;) a "&lt;FONT face="courier new,courier"&gt;1111&lt;/FONT&gt;" needs to be rounded and this is rounded &lt;STRONG&gt;&lt;EM&gt;up&lt;/EM&gt;&lt;/STRONG&gt; (because of the leading 1), which compensates the previous rounding error and leads to the proper internal binary representation of the integer 111701.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 23:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/954979#M372967</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-01-02T23:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: INT function returning unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/955213#M373063</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;An excellent, cogent, and detailed description of this situation. I learned something today - thank you for sharing it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 13:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INT-function-returning-unexpected-results/m-p/955213#M373063</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2025-01-06T13:46:22Z</dc:date>
    </item>
  </channel>
</rss>

