<?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: Real number tolerance and if() in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824459#M49399</link>
    <description>&lt;P&gt;One can also use:&lt;/P&gt;
&lt;P&gt;if (abs(A-Target) &amp;lt; SPACING(Target)) ...&lt;/P&gt;
&lt;P&gt;SPACING gives you the distance between the argument and the next representable value. You might want to use 2.0*SPACING to be "fuzzier". The Fortran EPSILON intrinsic is not useful for this as it always returns the spacing near 1.0.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Feb 2007 18:04:13 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2007-02-22T18:04:13Z</dc:date>
    <item>
      <title>Real number tolerance and if()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824454#M49394</link>
      <description>&lt;P&gt;After reading Doctor Fortran's article on 'The Perils of Real Numbers, Part 1', Iexperimented with some old code and found the following:&lt;/P&gt;
&lt;P&gt;REAL Sigma&lt;BR /&gt;CHARACTER(50) sStr&lt;BR /&gt;&lt;BR /&gt;if(Sigma .GT. 6.3) RETURN&lt;/P&gt;
&lt;P&gt;write(sStr, '(F35.30)') Sigma&lt;BR /&gt;..&lt;/P&gt;
&lt;P&gt;Program did not RETURNand sStr valuewas&lt;BR /&gt; ' 6.3000001907348632815', so Sigma was .GT. 6.3.How is it possible for Sigma.GT. 6.3 to be evaluated as .FALSE.?&lt;/P&gt;
&lt;P&gt;Thanks for any replies.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2007 21:55:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824454#M49394</guid>
      <dc:creator>gelarimer</dc:creator>
      <dc:date>2007-02-21T21:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Real number tolerance and if()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824455#M49395</link>
      <description>&lt;P&gt;That was Dave Eklund's article, not mine, but..&lt;/P&gt;
&lt;P&gt;Perhaps you need to read it again. Decimal fractions are often not exactly representable in binary floating point. 6.3 is one of them. Compile and run this program and then think about your question.&lt;/P&gt;&lt;PRE&gt;write (*,'(F35.30)') 6.3&lt;BR /&gt;end&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Feb 2007 22:23:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824455#M49395</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-02-21T22:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Real number tolerance and if()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824456#M49396</link>
      <description>&lt;P&gt;Also you don't convert until after you have tested sigma. The contents of the character variable are irrelevant - you're not testing that and it has not yet affected the value of the variable you are testing.&lt;/P&gt;
&lt;P&gt;What is the value of Sigma when you carry out the test, if its undefined you can expect erratic behaviour, somtimes it will return other times not.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2007 10:04:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824456#M49396</guid>
      <dc:creator>greldak</dc:creator>
      <dc:date>2007-02-22T10:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Real number tolerance and if()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824457#M49397</link>
      <description>Sigma was read fromafilecontaing the text6.3. What I failed to understand was that both the variable Sigma = 6.3and the constant 6.3 are representedthe same in memory and both representationsare not exact, so if(6.3000001907.. .GT. 6.3000001907..) evaluates to .FALSE.</description>
      <pubDate>Thu, 22 Feb 2007 10:40:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824457#M49397</guid>
      <dc:creator>gelarimer</dc:creator>
      <dc:date>2007-02-22T10:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Real number tolerance and if()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824458#M49398</link>
      <description>&lt;P&gt;The number 6.3 cannot be represented using the internal storage format for floating point numbers. This is true regardless of if the number stored is REAL(4), REAL(8), REAL(16). This is due to 0.1 being an infinately long repeting binary fraction. (0.3 will also be infinately long). The internal representation can store a number that is approximately 6.3 to within one bit value of the precision of the storage format (4, 8, 16 byte) for the particular number being represented. This characteristic is similar to rounding but it would more properly be described as uncertanty.&lt;/P&gt;
&lt;P&gt;The IF test compares the internal formats of the two numbers (or expressions) under the assumption that there is no uncertanty in the precision. Therefor, depending on how 6.3 is derived in the program you will either end up with 6.3+uncertanty or 6.3-uncertanty. Were the magnitude of the uncertanty is less than one bit of the precision of the number being represented.&lt;/P&gt;
&lt;P&gt;To program arround this, the technique used generaly encorporates a value called epsilon. The value of epsilon is chosen such that it is larger than the largest "uncertanty" for the expected numbers to be examined with the IF statement.&lt;/P&gt;
&lt;P&gt;Note that the value of uncertanty is different for 6.3 than for 1234.3. If you know what the value ranges are in advance, you can hard wire the epsilon. If not, then prior to the IF you can compute the epsilon, or compute a number approximately equal to your desired epsilon,using the Fortran function EPSILON(x). Where x is a variable of the same type as those to be examined in the IF test.&lt;/P&gt;
&lt;P&gt;When you have an epsilon&lt;/P&gt;
&lt;P&gt;if((A .gt. (Target - epsilon)) .and. (A .lt. (Target + epsilon)) call FoundA()&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2007 17:26:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824458#M49398</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2007-02-22T17:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Real number tolerance and if()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824459#M49399</link>
      <description>&lt;P&gt;One can also use:&lt;/P&gt;
&lt;P&gt;if (abs(A-Target) &amp;lt; SPACING(Target)) ...&lt;/P&gt;
&lt;P&gt;SPACING gives you the distance between the argument and the next representable value. You might want to use 2.0*SPACING to be "fuzzier". The Fortran EPSILON intrinsic is not useful for this as it always returns the spacing near 1.0.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2007 18:04:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824459#M49399</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-02-22T18:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Real number tolerance and if()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824460#M49400</link>
      <description>Thanks JimSteve. Very helpful information. I have been searching on the web for any information/discussions that would help explain aspects of Real Numbers and programming as you have above. D&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;a&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;v&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;e&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt; &lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;E&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;k&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;l&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;u&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;n&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;d&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;'&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;s&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt; &lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;a&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;r&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;t&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;i&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;c&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;l&lt;SPAN style="COLOR: black; BACKGROUND-COLOR: yellow"&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;e 'The Perils of Real Numbers' was a good starting point, and some class room lectures (found on the web)on the IEEE Real Number standard shed some light on that subject, butwould like to geta deeper insight. Is there an in-depth text or reference that would cover the subject from A to Z?</description>
      <pubDate>Sat, 24 Feb 2007 00:47:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824460#M49400</guid>
      <dc:creator>gelarimer</dc:creator>
      <dc:date>2007-02-24T00:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Real number tolerance and if()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824461#M49401</link>
      <description>&lt;P&gt;I haven't run across such myself but I'm not exposed to such things as much as some. I'm sure that if you asked this in comp.lang.fortran you'd get some good pointers. A brief web search turns up a similarly-named article &lt;A href="http://www.lahey.com/float.htm"&gt;The Perils of Floating Point&lt;/A&gt; which I often see cited. When I was in college, I learned a lot from Volume 2 of Donald Knuth's "The Art of Computer Programming" (my favorite of the three volumes that had been published.) Perhaps others here will have additional suggestions. &lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2007 01:16:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824461#M49401</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-02-24T01:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Real number tolerance and if()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824462#M49402</link>
      <description>Thanks Steve, appreciate the help and references.</description>
      <pubDate>Sat, 24 Feb 2007 13:59:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Real-number-tolerance-and-if/m-p/824462#M49402</guid>
      <dc:creator>gelarimer</dc:creator>
      <dc:date>2007-02-24T13:59:23Z</dc:date>
    </item>
  </channel>
</rss>

