<?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 &amp;gt;&amp;gt;...Just a point of order - in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955618#M93290</link>
    <description>&amp;gt;&amp;gt;...Just a point of order - while I reposted the "Perils of Real Numbers" articles in this forum, they were written by compiler
&amp;gt;&amp;gt;developer Dave Eklund for the original Digital Visual Fortran newsletter...

Could you make a Sticky Post with links to these articles, and another as well, please? Thanks.</description>
    <pubDate>Sat, 20 Jul 2013 00:30:33 GMT</pubDate>
    <dc:creator>SergeyKostrov</dc:creator>
    <dc:date>2013-07-20T00:30:33Z</dc:date>
    <item>
      <title>Incorrect Results - Floating Point Issue?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955605#M93277</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I am having an issue with a very simple calculation that ends up having "incorrect" results.&lt;/P&gt;
&lt;P&gt;VOLUME, LENGTH, WIDTH and THICK&amp;nbsp;are declared as REAL&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;VOLUME = (LENGTH / 1000.) * (WIDTH / 1000.) * (THICK / 1000.)&lt;/P&gt;
&lt;P&gt;When I use the following values:&lt;BR /&gt;length = 130 ; width=95 ; thick=14&lt;BR /&gt;The debugger shows 1.7289999E-04. Yet I am expecting 1.729E-04 as a result.&lt;/P&gt;
&lt;P&gt;I tried declaring VOLUME as REAL*8, yet this did not help. So I tried to change the FloatingPoint settings (eventhough I really don't understand any of their meanings). So far I did not manage to&amp;nbsp;get the "correct" result.&lt;BR /&gt;&lt;BR /&gt;Does anyone know which FloatingPoint Settings (or other settings which&amp;nbsp;I haven't thought about) I have to use to get the "correct" results?&lt;BR /&gt;Or are those "incorrect" result normal with Fortran?&lt;/P&gt;
&lt;P&gt;Thanks for your Help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2013 08:35:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955605#M93277</guid>
      <dc:creator>FortranBeginner</dc:creator>
      <dc:date>2013-07-19T08:35:44Z</dc:date>
    </item>
    <item>
      <title>It will be very useful for</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955606#M93278</link>
      <description>&lt;BLOCKQUOTE&gt;Yet I am expecting 1.729E-04 as a result.&lt;/BLOCKQUOTE&gt; That expectation is based on performing calculations using decimal floating point calculation. Real*4 variables are stored in the form ±&lt;I&gt;a&lt;/I&gt; ×2&lt;I&gt;&lt;SUP&gt;b&lt;/SUP&gt;,&amp;nbsp;&lt;/I&gt;where &lt;I&gt;a&lt;/I&gt; and &lt;I&gt;b&lt;/I&gt; are integers represented in 24 and 8 bits, respectively&lt;SUP&gt;*&lt;/SUP&gt;, and floating point arithmetic is done in binary IEEE. The number in question (1.729E-04)&amp;nbsp;cannot be represented exactly in the number of bits available. In fact, even the simpler number 0.1 does not have an exact representation as a REAL*4 constant.&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;It will be very useful for you to read enough about floating point arithmetic that findings such as this no longer perturb you. Among many articles, &amp;nbsp;you may&amp;nbsp;read&amp;nbsp;&lt;A href="http://docs.oracle.com/cd/E19957-01/800-7895/800-7895.pdf"&gt;http://docs.oracle.com/cd/E19957-01/800-7895/800-7895.pdf&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Here is an instructive example:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;program f3&lt;BR /&gt;real x,y,z&lt;BR /&gt;data x,y,z/4.0,3.0,1.0/&lt;BR /&gt;print *,z-(x/y-1)*y&lt;BR /&gt;end[/fortran]&lt;/P&gt;
&lt;P&gt;Compile and run the example, and compare the result with what you get using (i) manual calculation and (ii) one or more calculators.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;I tried declaring VOLUME as REAL*8, yet this did not help.&lt;/BLOCKQUOTE&gt;It should make no difference, because the expression on the right hand side is of type REAL*4. Try declaring WIDTH, LENGTH and THICK as REAL*8.&lt;P&gt;&lt;/P&gt;
&lt;P&gt;___________________&lt;/P&gt;
&lt;P&gt;&lt;SUP&gt;*&lt;/SUP&gt; The exponent is adjusted with a bias such that the mantissa lies between 1 and 2, and its leading bit is implicitly = 1, but these details are less important.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2013 08:51:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955606#M93278</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2013-07-19T08:51:00Z</dc:date>
    </item>
    <item>
      <title>Your example showed</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955607#M93279</link>
      <description>&lt;P&gt;Your example showed assignments of integers to single precision floating point variables. The integers will get converted in the assignment so when you change the declaration of the variables&amp;nbsp;to *8, &amp;nbsp;the assigned values should be as precise as you might expect. However if you assign using:&lt;/P&gt;
&lt;P&gt;length = 130.0 ; width=95.0; thick=14.0&lt;/P&gt;
&lt;P&gt;You will then only have single precsion accuracy constants assigned to double precsion variables. Here is a better way to assign constants to double precision variables:&lt;/P&gt;
&lt;P&gt;length = 130.0_8 ; width=95.0_8 ; thick=14.0_8&lt;/P&gt;
&lt;P&gt;or the old fashioned:&lt;/P&gt;
&lt;P&gt;length = 130.0D0; width=95.0D0 ; thick=14.0D0&lt;/P&gt;
&lt;P&gt;Other languages have their own notations for precision of floating point constants.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2013 09:55:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955607#M93279</guid>
      <dc:creator>Andrew_Smith</dc:creator>
      <dc:date>2013-07-19T09:55:47Z</dc:date>
    </item>
    <item>
      <title>Steve Lionel (as Dr Fortran)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955608#M93280</link>
      <description>&lt;P&gt;Steve Lionel (as Dr Fortran) has published&amp;nbsp;much useful information covering this and other points which you may find interesting.&lt;/P&gt;
&lt;P&gt;see &lt;A href="http://software.intel.com/en-us/forums/topic/275071"&gt;http://software.intel.com/en-us/forums/topic/275071&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in particular the "Perils of Real Numbers" parts 1 2 and 3&lt;/P&gt;
&lt;P&gt;Les&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2013 10:07:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955608#M93280</guid>
      <dc:creator>Les_Neilson</dc:creator>
      <dc:date>2013-07-19T10:07:12Z</dc:date>
    </item>
    <item>
      <title>Thanks both for your help.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955609#M93281</link>
      <description>&lt;P&gt;Thanks both for your help.&lt;/P&gt;
&lt;P&gt;Declaring all variables as REAL*8 solved the problem. &lt;BR /&gt;I now also know how to assign constants properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2013 11:58:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955609#M93281</guid>
      <dc:creator>FortranBeginner</dc:creator>
      <dc:date>2013-07-19T11:58:48Z</dc:date>
    </item>
    <item>
      <title>FortranBeginner,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955610#M93282</link>
      <description>&lt;P&gt;FortranBeginner,&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;Declaring all variables as REAL*8 solved the problem. &lt;BR /&gt;It may have hid the problem.&lt;/P&gt;
&lt;P&gt;The problem is some nice clean decimal fractions cannot be stored in a finite number of bits as a binary fraction. 0.1 is a good example:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;real(4) :: r4&lt;BR /&gt;real(8) :: r8fromr4, r8&lt;BR /&gt;r4 = 0.1&lt;BR /&gt;r8fromr4 = r4&lt;BR /&gt;r8 = 0.1_8&lt;/P&gt;
&lt;P&gt;Watch Window&lt;BR /&gt;R8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.100000000000000 REAL(8) &lt;BR /&gt;R8FROMR4 0.100000001490116 REAL(8) &lt;BR /&gt;R4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.1000000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REAL(4)&lt;/P&gt;
&lt;P&gt;Looks good eh.&lt;/P&gt;
&lt;P&gt;Now choose Hexadecimal display&lt;/P&gt;
&lt;P&gt;R8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #3FB999999999999A REAL(8) &lt;BR /&gt;R8FROMR4 #3FB99999A0000000 REAL(8) &lt;BR /&gt;R4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #3DCCCCCD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REAL(4)&lt;BR /&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;0.1 produces a repeating binary fraction (similar to 1/3 producing a repeating decimal fraction)&lt;/P&gt;
&lt;P&gt;The decimal display is showing you the rounded number&lt;BR /&gt;The Hexadecimal display discloses two things:&lt;BR /&gt;a) the ...9999A is indicitive of rounding a repeating fraction (same with ...CCCCD)&lt;BR /&gt;b) the R8FROMR4 shows the truncation effect of an assignment of a&amp;nbsp;rounded real(4) number.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2013 12:33:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955610#M93282</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-07-19T12:33:26Z</dc:date>
    </item>
    <item>
      <title>I tried to post this earlier</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955611#M93283</link>
      <description>&lt;P&gt;I tried to post this earlier but it hasn't arrived yet.&lt;BR /&gt;You may find Steve's Dr Fortran articles helpful&lt;BR /&gt;see &lt;A href="http://software.intel.com/en-us/forums/topic/275071"&gt;http://software.intel.com/en-us/forums/topic/275071&lt;/A&gt;&lt;BR /&gt;especially "The Perils of Real Numbers" parts 1,2, and 3&lt;BR /&gt;Les&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2013 13:02:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955611#M93283</guid>
      <dc:creator>Les_Neilson</dc:creator>
      <dc:date>2013-07-19T13:02:46Z</dc:date>
    </item>
    <item>
      <title>&gt;&gt;...The debugger shows 1</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955612#M93284</link>
      <description>&amp;gt;&amp;gt;...The debugger shows &lt;STRONG&gt;1.7289999E-04&lt;/STRONG&gt;. Yet I am expecting &lt;STRONG&gt;1.729E-04&lt;/STRONG&gt; as a result.

There is some &lt;STRONG&gt;UI issue&lt;/STRONG&gt; with several Visual Studios, like 2005, 2008, etc. I see such "mis-roundings" every day when debugging codes and verifying results of some computations. However, if actual &lt;STRONG&gt;binary&lt;/STRONG&gt; results are different from what you're expecting then there is some problem and, of course, it needs to be investigated. I will also take a look at your test case.</description>
      <pubDate>Fri, 19 Jul 2013 14:07:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955612#M93284</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2013-07-19T14:07:59Z</dc:date>
    </item>
    <item>
      <title>Quote:Sergey Kostrov wrote:I</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955613#M93285</link>
      <description>&lt;BLOCKQUOTE&gt;Sergey Kostrov wrote:&lt;BR /&gt;I see such "mis-roundings" every day&lt;/BLOCKQUOTE&gt;Why do you think that this is an instance of "mis-rounding"? Looking at the OP's example in the VS debugger, using REAL*4 for all variables, and asking the debugger to show values in hexadecimal, for the volume I see 0x39354C7D, which is closer to the exact result, 1.729E-4, than the next closest machine number, 0x39354C7E. The number of decimal digits shown by the debugger is consistent with the 24-bit precision of REAL*4 -- it shows eight significant decimal digits; 24 bits corresponds to 24 log&lt;SUB&gt;10&lt;/SUB&gt;2 = 7.22 decimal digits.&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;For more advanced applications, finer control over the conversion of the internal representation to decimal output is afforded by the format control edit descriptors RU, RD, RZ, RN, RC, and RP.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2013 14:42:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955613#M93285</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2013-07-19T14:42:00Z</dc:date>
    </item>
    <item>
      <title>Just a point of order - while</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955614#M93286</link>
      <description>&lt;P&gt;Just a point of order - while I reposted the "Perils of Real Numbers" articles in this forum, they were written by compiler developer Dave Eklund for the original Digital Visual Fortran newsletter.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2013 16:39:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955614#M93286</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-07-19T16:39:09Z</dc:date>
    </item>
    <item>
      <title>FortranBeginner, Let me go</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955615#M93287</link>
      <description>FortranBeginner, Let me go back to your questions from the Initial post.

&amp;gt;&amp;gt;...The debugger shows 1.7289999E-04. Yet I am expecting 1.729E-04 as a result...

This is Not from the Debugger because Visual Studio has an Expression Evaluation software subsystem ( UI ) and it is used to &lt;STRONG&gt;display everything&lt;/STRONG&gt;, like ( A + B - C ), in the Watch Window.

&amp;gt;&amp;gt;...Does anyone know which FloatingPoint Settings (or other settings which I haven't thought about) I have to use to get the "correct" results?

There are no such Unknown Floating-Point Unit settings. Once again, the Expression Evaluation software subsystem ( 1st ) and Floating-Point Unit settings ( 2nd and it is controled from a command line of the compiler or at runtime ) are Not related directly. The 1st one simply displays any values,depending on a data type, or expression(s), and it could have its own Rounding limitations.

&amp;gt;&amp;gt;...Or are those "incorrect" result normal with Fortran?

No. I would say the following: your program should produce correct results at runtime in Release Configuration and verify it first of all.

Also, take a look at two screenshots.</description>
      <pubDate>Sat, 20 Jul 2013 00:18:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955615#M93287</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2013-07-20T00:18:00Z</dc:date>
    </item>
    <item>
      <title>Screenshot #1:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955616#M93288</link>
      <description>Screenshot #1:

&lt;span class="lia-inline-image-display-wrapper" image-alt="watchvolumevalue.jpg"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/10136i2150708DB7CD7456/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="watchvolumevalue.jpg" alt="watchvolumevalue.jpg" /&gt;&lt;/span&gt;

Note: Even if it is for VS 2005 you see that everything is correct.</description>
      <pubDate>Sat, 20 Jul 2013 00:24:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955616#M93288</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2013-07-20T00:24:40Z</dc:date>
    </item>
    <item>
      <title>Screenshot #2:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955617#M93289</link>
      <description>Screenshot #2:

&lt;span class="lia-inline-image-display-wrapper" image-alt="outputvolumevalue.jpg"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/10137i73A8729ABBFB3E8B/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="outputvolumevalue.jpg" alt="outputvolumevalue.jpg" /&gt;&lt;/span&gt;

Note: At runtime it also shows a correct result.</description>
      <pubDate>Sat, 20 Jul 2013 00:27:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955617#M93289</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2013-07-20T00:27:35Z</dc:date>
    </item>
    <item>
      <title>&gt;&gt;...Just a point of order -</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955618#M93290</link>
      <description>&amp;gt;&amp;gt;...Just a point of order - while I reposted the "Perils of Real Numbers" articles in this forum, they were written by compiler
&amp;gt;&amp;gt;developer Dave Eklund for the original Digital Visual Fortran newsletter...

Could you make a Sticky Post with links to these articles, and another as well, please? Thanks.</description>
      <pubDate>Sat, 20 Jul 2013 00:30:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955618#M93290</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2013-07-20T00:30:33Z</dc:date>
    </item>
    <item>
      <title>See the "Useful Information</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955619#M93291</link>
      <description>&lt;P&gt;See the "Useful Information and Frequently Asked Questions" link in the forum header.&amp;nbsp; Links are in that article. I didn't want to clutter the forum with lots of sticky posts.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jul 2013 00:34:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Incorrect-Results-Floating-Point-Issue/m-p/955619#M93291</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-07-20T00:34:21Z</dc:date>
    </item>
  </channel>
</rss>

