Boost C++ Libraries: Ticket #9748: cyl_bessel_j returns incorrect sign when using --fast-math on GCC or -std=c++11 on Intel Compiler https://svn.boost.org/trac10/ticket/9748 <p> The cyl_bessel_j function returns the incorrect sign for certain inputs when using GCC's --fast-math flag, or the Intel compiler's -std=c++11. </p> <p> This bug has been shown to affect GCC 4.4.7 as delivered in RHEL 6.3 and the Intel compiler version 13.1.3 20130607 on the same OS. </p> <p> The following minimal case program can replicate the problem: </p> <pre class="wiki">#include &lt;boost/math/special_functions/bessel.hpp&gt; #include &lt;iostream&gt; int main(int argc, char** argv) { double besselTerm = boost::math::cyl_bessel_j(1.5, 7.90559); std::cout &lt;&lt; besselTerm &lt;&lt; std::endl; } </pre><p> When this program is compiled under GCC with the --fast-math flag, or ICPC with the -std=c++11 flag, it gives a result of -0.0504874. Checking this answer against a reference MATLAB implementation, or GCC 4.1.2 shows that the correct answer should be 0.0504874. When compiled on GCC 4.4.7 *without* the --fast-math flag, or ICPC without the -std=c++11 flag, the correct answer is returned. </p> <p> This behavior has been found for all inputs of P from 1.5 to 30.5 with the same Z input of 7.90559. Other values of Z can cause the problem as well, but have not been included here for brevity. Note that not all combinations of P and Z give invalid results, just some do, and the behavior is always that the sign is wrong (the absolute value is correct). Using the --fast-math flag on older versions of GCC produces the correct result. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9748 Trac 1.4.3 Dustin Lanham <lanhamd@…> Thu, 06 Mar 2014 17:06:09 GMT <link>https://svn.boost.org/trac10/ticket/9748#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9748#comment:1</guid> <description> <p> Addendum: This behavior was noted in two separate versions of boost: 1.50.0 and 1.55.0. </p> </description> <category>Ticket</category> </item> <item> <author>Dustin Lanham <lanhamd@…></author> <pubDate>Thu, 06 Mar 2014 22:28:02 GMT</pubDate> <title>component changed; owner set https://svn.boost.org/trac10/ticket/9748#comment:2 https://svn.boost.org/trac10/ticket/9748#comment:2 <ul> <li><strong>owner</strong> set to <span class="trac-author">John Maddock</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">math</span> </li> </ul> Ticket John Maddock Sun, 09 Mar 2014 18:40:46 GMT <link>https://svn.boost.org/trac10/ticket/9748#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9748#comment:3</guid> <description> <p> To a degree, this is not our bug, a reduced test case is simply: </p> <pre class="wiki"> long double ld = -5.3165867831218916301793863361917824e-2467L; std::cout &lt;&lt; std::signbit(ld) &lt;&lt; std::endl; </pre><p> Which incorrectly outputs 0 when compiling with --fast-math. </p> <p> I suspect there may be other std lib functions which have similar issues too, I'll investigate working around this one, but you may just get whacked by another... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 10 Mar 2014 09:43:06 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9748#comment:4 https://svn.boost.org/trac10/ticket/9748#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fix is here: <a class="ext-link" href="https://github.com/boostorg/math/commit/9f8ffee4b7a3f82b1c582735d43522d7d0cde746"><span class="icon">​</span>https://github.com/boostorg/math/commit/9f8ffee4b7a3f82b1c582735d43522d7d0cde746</a> </p> <p> As an alternative, define BOOST_MATH_DISABLE_STD_FPCLASSIFY when building. </p> Ticket