Boost C++ Libraries: Ticket #6307: problem in bessel_jn https://svn.boost.org/trac10/ticket/6307 <p> In bessel_jn (math/special_functions/detail) line 75 reads: </p> <p> if((tools::max_value&lt;T&gt;() - fabs(prev)) / fabs(fact) &lt; fabs(current)) </p> <p> fact is defined in line 74: </p> <p> T fact = 2 * k / x; </p> <p> when k is 1 and x &gt; 2 , fact &lt; 1 resulting in </p> <p> ((tools::max_value&lt;T&gt;() - fabs(prev)) / fabs(fact) </p> <p> to be bigger then tools::max_value&lt;T&gt;(), resulkting in an error. </p> <p> I have change line 75 into </p> <p> if((tools::max_value&lt;T&gt;() - fabs(prev)) &lt; fabs(fact) * fabs(current)) </p> <p> and made the same change for line 100. </p> <p> With this fix, the code runs and produces (in my limited testing) the same numbers as octave does. I am not sure if it is a general fix though. </p> <p> The problem occurred on this architecture: </p> <p> Linux syrah.als.lbl.gov 2.6.35.14-97.fc14.x86_64 <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 Sat Sep 17 00:15:37 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux </p> <p> svn diff gives this: </p> <p> =================================================================== --- bessel_jn.hpp (revision 76082) +++ bessel_jn.hpp (working copy) @@ -72,7 +72,7 @@ </p> <blockquote> <p> for (int k = 1; k &lt; n; k++) { </p> <blockquote> <p> T fact = 2 * k / x; </p> </blockquote> </blockquote> <ul><li> if((tools::max_value&lt;T&gt;() - fabs(prev)) / fabs(fact) &lt; fabs(current)) </li></ul><p> + if((tools::max_value&lt;T&gt;() - fabs(prev)) &lt; fabs(fact) * fabs(current)) </p> <blockquote> <p> { </p> <blockquote> <p> scale /= current; prev /= current; </p> </blockquote> </blockquote> <p> @@ -97,7 +97,7 @@ </p> <blockquote> <p> for (int k = n; k &gt; 0; k--) { </p> <blockquote> <p> T fact = 2 * k / x; </p> </blockquote> </blockquote> <ul><li> if((tools::max_value&lt;T&gt;() - fabs(prev)) / fact &lt; fabs(current)) </li></ul><p> + if((tools::max_value&lt;T&gt;() - fabs(prev)) &lt; fabs(fact) * fabs(current)) </p> <blockquote> <p> { </p> <blockquote> <p> prev /= current; scale /= current; </p> </blockquote> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6307 Trac 1.4.3 John Maddock Wed, 21 Dec 2011 16:46:49 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6307#comment:1 https://svn.boost.org/trac10/ticket/6307#comment:1 <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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/76094" title="Delete unneeded variable. Fixes #6307.">[76094]</a>) Delete unneeded variable. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6307" title="#6307: Bugs: problem in bessel_jn (closed: fixed)">#6307</a>. </p> Ticket John Maddock Wed, 21 Dec 2011 16:58:38 GMT <link>https://svn.boost.org/trac10/ticket/6307#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6307#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/76095" title="Change overflow tests to not generate an infinity. Fixes #6307.">[76095]</a>) Change overflow tests to not generate an infinity. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6307" title="#6307: Bugs: problem in bessel_jn (closed: fixed)">#6307</a>. </p> </description> <category>Ticket</category> </item> </channel> </rss>