<?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 Strange bug with different method of adding in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015505#M106980</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a CFD code whereby in a subroutine, I have to calculate the angle theta_x_rad. I calculate it using:&lt;/P&gt;

&lt;P&gt;theta_x_rad = &lt;STRONG&gt;-&lt;/STRONG&gt; 0.5d0*omega_r_max*(tmp_time2 - (0.5d0*dt_r/Pi)*sin(2.d0*Pi*(tmp_time2 + 0.5d0*dt_r)/dt_r)) + k_r1 (= 1.57, given by print)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	theta_x_rad = &lt;STRONG&gt;-&lt;/STRONG&gt; theta_x_rad + Pi&lt;/P&gt;

&lt;P&gt;I got the correct ans, which is ~1.569. Now if I do it in this way:&lt;/P&gt;

&lt;P&gt;theta_x_rad = 0.5d0*omega_r_max*(tmp_time2 - (0.5d0*dt_r/Pi)*sin(2.d0*Pi*(tmp_time2 + 0.5d0*dt_r)/dt_r)) + k_r1 + Pi (no minus sign in front)&lt;/P&gt;

&lt;P&gt;I got 4.71. It seems that the 1st term above is calculated as 1.57 instead of -1.57&lt;/P&gt;

&lt;P&gt;I tried different intel versions, debug, opt etc, but the ans are the same.&lt;/P&gt;

&lt;P&gt;Did I miss out on something?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 May 2014 02:45:03 GMT</pubDate>
    <dc:creator>Wee_Beng_T_</dc:creator>
    <dc:date>2014-05-15T02:45:03Z</dc:date>
    <item>
      <title>Strange bug with different method of adding</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015505#M106980</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a CFD code whereby in a subroutine, I have to calculate the angle theta_x_rad. I calculate it using:&lt;/P&gt;

&lt;P&gt;theta_x_rad = &lt;STRONG&gt;-&lt;/STRONG&gt; 0.5d0*omega_r_max*(tmp_time2 - (0.5d0*dt_r/Pi)*sin(2.d0*Pi*(tmp_time2 + 0.5d0*dt_r)/dt_r)) + k_r1 (= 1.57, given by print)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	theta_x_rad = &lt;STRONG&gt;-&lt;/STRONG&gt; theta_x_rad + Pi&lt;/P&gt;

&lt;P&gt;I got the correct ans, which is ~1.569. Now if I do it in this way:&lt;/P&gt;

&lt;P&gt;theta_x_rad = 0.5d0*omega_r_max*(tmp_time2 - (0.5d0*dt_r/Pi)*sin(2.d0*Pi*(tmp_time2 + 0.5d0*dt_r)/dt_r)) + k_r1 + Pi (no minus sign in front)&lt;/P&gt;

&lt;P&gt;I got 4.71. It seems that the 1st term above is calculated as 1.57 instead of -1.57&lt;/P&gt;

&lt;P&gt;I tried different intel versions, debug, opt etc, but the ans are the same.&lt;/P&gt;

&lt;P&gt;Did I miss out on something?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2014 02:45:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015505#M106980</guid>
      <dc:creator>Wee_Beng_T_</dc:creator>
      <dc:date>2014-05-15T02:45:03Z</dc:date>
    </item>
    <item>
      <title>Check the sign of the term k</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015506#M106981</link>
      <description>&lt;P&gt;Check the sign of the term&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp;k_r1 in the line on which you commented "no minus sign".&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2014 03:33:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015506#M106981</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2014-05-15T03:33:00Z</dc:date>
    </item>
    <item>
      <title>Hi mecej4,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015507#M106982</link>
      <description>&lt;P&gt;Hi mecej4,&lt;/P&gt;

&lt;P&gt;It's a predefined variable and it's ~ 1.57. I checked too.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2014 06:30:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015507#M106982</guid>
      <dc:creator>Wee_Beng_T_</dc:creator>
      <dc:date>2014-05-15T06:30:34Z</dc:date>
    </item>
    <item>
      <title>Here is the clarification of</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015508#M106983</link>
      <description>&lt;P&gt;Here is the clarification of my comment, which was about the expression and not the declaration or definition of k_r1.&lt;/P&gt;

&lt;P&gt;You wrote:&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;theta_x_rad = 0.5d0*omega_r_max*(tmp_time2 - (0.5d0*dt_r/Pi)*sin(2.d0*Pi*(tmp_time2 + 0.5d0*dt_r)/dt_r)) &lt;STRONG&gt;+&lt;/STRONG&gt; k_r1 + Pi (no minus sign in front)&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;The + sign attached to k_r1 is not consistent with what you get from combining the two preceding assignment statements in your original post. Algebra rules say that you should have written&amp;nbsp;&lt;STRONG&gt;-&lt;/STRONG&gt; k_r1 instead.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;I suspect that the leading term is negligibly small. If so, the three statements in questions could be written as follows:&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;&amp;nbsp; &amp;nbsp; theta_x_rad =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;&amp;nbsp;+ k_r1&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;&amp;nbsp; &amp;nbsp; theta_x_rad =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-weight: 700; font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;-&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;&amp;nbsp;theta_x_rad + Pi&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;&amp;nbsp; &amp;nbsp; theta_x_rad =&amp;nbsp;+ k_r1 + Pi &amp;nbsp;&amp;lt;&amp;lt;&amp;lt;===== &amp;nbsp;&lt;STRONG&gt;Error:&lt;/STRONG&gt; the first '+' should be '-'&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;If k_r1 is close to π/&amp;nbsp;2 (≈ 1.57), the first two statements taken together yield the result π/2, whereas the third, because of the erroneous sign, yields 3 π / 2 (≈ 4.71&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 11.818181991577148px; line-height: 16.363636016845703px;"&gt;In other words, the culprit is an error in algebraic simplification and not anything involving programming, Fortran, or compiler options.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2014 13:45:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015508#M106983</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2014-05-15T13:45:00Z</dc:date>
    </item>
    <item>
      <title>Hmm, still don't really</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015509#M106984</link>
      <description>&lt;P&gt;Hmm, still don't really understand. I'll check with some other values and get back to you.&lt;/P&gt;

&lt;P&gt;Thanks&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 May 2014 01:06:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015509#M106984</guid>
      <dc:creator>Wee_Beng_T_</dc:creator>
      <dc:date>2014-05-17T01:06:09Z</dc:date>
    </item>
    <item>
      <title>Well, let's try something</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015510#M106985</link>
      <description>&lt;P&gt;Well, let's try something different. The two sequential assignments&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;x = -a + b&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;x = -x + c&lt;/P&gt;

&lt;P&gt;cause x to have the final value a &lt;STRONG&gt;-&lt;/STRONG&gt; b + c&lt;/P&gt;

&lt;P&gt;Your third assignment (the alternative), on the other hand, causes x to have the value a &lt;STRONG&gt;+&lt;/STRONG&gt; b + c. The second term in this "result" has an incorrect sign.&lt;/P&gt;

&lt;P&gt;That is the crux of the matter, and you really do not need to try different values, etc.; simply recollect and apply the rules of algebra.&lt;/P&gt;</description>
      <pubDate>Sat, 17 May 2014 03:20:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015510#M106985</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2014-05-17T03:20:00Z</dc:date>
    </item>
    <item>
      <title>Ops ... I saw it!</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015511#M106986</link>
      <description>&lt;P&gt;Ops ... I saw it!&lt;/P&gt;

&lt;P&gt;It should be:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;x = a - b + c, but I gave it x = a + b +c !&lt;/P&gt;

&lt;P&gt;It's so embarrassing. I just can't see it intially... Thanks again!&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 May 2014 04:55:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Strange-bug-with-different-method-of-adding/m-p/1015511#M106986</guid>
      <dc:creator>Wee_Beng_T_</dc:creator>
      <dc:date>2014-05-18T04:55:15Z</dc:date>
    </item>
  </channel>
</rss>

