Boost C++ Libraries: Ticket #4812: Bug in boost::math::special_functions::sign showing up in special_functions::bessel_jy() https://svn.boost.org/trac10/ticket/4812 <p> Hi, </p> <p> When computing scattering curves, I encountered a show-stopping bug that I tracked back to the boost::math::special_functions::sign function . </p> <p> In math::special_functions::bessel_jy a small number is generated via </p> <p> sqrt(tools::min_value&lt;T&gt;()) </p> <p> which subsequently ends up in this statement: sign(current) </p> <p> I see this happening: </p> <p> variable current: -1.24911e-2468 variable sign(current): 1 </p> <p> which causes problems for math::special_functions::sph_bessel(1,x) for x between 7.845 and 8 or so on my machines. </p> <p> The fix that worked for me is the following </p> <blockquote> <p> T sign_current; sign_current = std::fabs(current); if (current*2.0 &lt; sign_current){ </p> <blockquote> <p> sign_current = -1.0; </p> </blockquote> <p> } else { </p> <blockquote> <p> sign_current = 1.0; </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> Ju = sign_current * sqrt(W / (q + gamma * (p - t))); <em> Ju = sign(current) * sqrt(W / (q + gamma * (p - t))); </em></p> </blockquote> <p> For now, I'll run with this local fix but it seems that on some platforms the current sign function causes problems when computing spherical Bessel functions of any order above 0. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4812 Trac 1.4.3 anonymous Thu, 04 Nov 2010 11:40:45 GMT <link>https://svn.boost.org/trac10/ticket/4812#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4812#comment:1</guid> <description> <p> Hi Peter, </p> <p> I'm unable to reproduce here, so I need your help as the implementation of boost::math::sign is platform/compiler dependent, so I have a bunch of questions for you I'm afraid: </p> <p> 1) What compiler / platform / architecture is this? 2) Can check the return value of boost::math::sign(-1.24911e-2468L); and verify that this returns an incorrect result? 3) If (2) does return an incorrect result, can you please step though it's code and let me know which of the implementations of signbit_impl in sign.hpp is in use? </p> <p> Many thanks, John Maddock. </p> </description> <category>Ticket</category> </item> <item> <author>phzwart@…</author> <pubDate>Fri, 05 Nov 2010 05:11:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4812#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4812#comment:2</guid> <description> <p> Hi, </p> <p> 1. </p> <p> uname -a gives </p> <p> Linux xxx.yyy.zzz.gov 2.6.33 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1" title="#1: Bugs: boost.build causes ftjam to segfault (closed: Wont Fix)">#1</a> SMP Mon Mar 1 16:05:57 PST 2010 x86_64 x86_64 x86_64 GNU/Linux </p> <p> localhost 8% g++ -v Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=<a class="ext-link" href="http://bugzilla.redhat.com/bugzilla"><span class="icon">​</span>http://bugzilla.redhat.com/bugzilla</a> --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-<span class="underline">cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-cpu=generic --build=x86_64-redhat-linux Thread model: posix gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC) </span></p> <p> 2. </p> <p> fault is there: </p> <p> -1.24911e-2468 1 </p> <p> 3. </p> <p> this one is used: </p> <p> #ifdef BOOST_MATH_USE_STD_FPCLASSIFY </p> <blockquote> <p> template&lt;class T&gt; inline int signbit_impl(T x, native_tag const&amp;) { </p> <blockquote> <p> return (std::signbit)(x); </p> </blockquote> <p> } </p> </blockquote> <p> #endif </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 05 Nov 2010 12:03:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4812#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4812#comment:3</guid> <description> <p> Thanks for the info, </p> <p> So am I correct in thinking that (std::signbit)(-1.24911e-2468L) returns 0? If so can you please file a bug report with the GNU libc guys? </p> <p> The fix will be to define BOOST_MATH_DISABLE_STD_FPCLASSIFY for those platforms that are effected... if we can figure out which those are. In the mean time I'll update our regression tests with this case and see what fails... </p> <p> Regards, John Maddock. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 05 Nov 2010 13:34:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4812#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4812#comment:4</guid> <description> <p> it returns 1. </p> <p> if it is a gnu libc issue, i'll file a bug report there as well. </p> <p> P </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 05 Nov 2010 13:55:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4812#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4812#comment:5</guid> <description> <blockquote class="citation"> <p> it returns 1. </p> </blockquote> <p> Then I'm confused as to why it's failing, are you in a position to debug </p> <p> boost::math::sign(-1.24911e-2468L); </p> <p> And figure out why it isn't returning -1? The code is so simple it's hard to see how it could go wrong really and I still can't reproduce here... </p> <p> Thanks, John. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 05 Nov 2010 14:05:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4812#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4812#comment:6</guid> <description> <blockquote> <p> #include &lt;iostream&gt; #include &lt;cmath&gt; int main(void){ </p> <blockquote> <p> std::cout &lt;&lt; "hello world " &lt;&lt; std::endl; </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> std::cout &lt;&lt; (std::signbit)(-1.24911e-2468L)&lt;&lt;std::endl;; </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> std::cout &lt;&lt; (std::signbit)(-2.24911e-2468L)&lt;&lt;std::endl;; </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> std::cout &lt;&lt; (std::signbit)(-3.24911)&lt;&lt;std::endl; </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> std::cout &lt;&lt; (std::signbit)(3.24911)&lt;&lt;std::endl; </p> </blockquote> </blockquote> <blockquote> <p> } </p> </blockquote> <p> gives </p> <p> 1 1 1 0 </p> <p> Not much time for debugging this right at the moment, i'll try tonight. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Thu, 11 Nov 2010 16:43:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4812#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4812#comment:7</guid> <description> <p> Any news on this? </p> <p> I've updated our regression tests with both the sph_bessel test case you give, and the sign case, and both seem to be passing on our test machines. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 11 Nov 2010 17:44:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4812#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4812#comment:8</guid> <description> <p> No, sorry not time yet to dig further. I hope to get to it in the next couple of days. </p> <p> Sorry, </p> <p> P </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Thu, 06 Jan 2011 11:27:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4812#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4812#comment:9</guid> <description> <p> Ping? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 10 Oct 2011 08:54:16 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4812#comment:10 https://svn.boost.org/trac10/ticket/4812#comment:10 <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">worksforme</span> </li> </ul> <p> I need more info to deal with this, so I'm closing for now, please reopen if you can provide the needed info. </p> Ticket