Boost C++ Libraries: Ticket #10985: Logically dead code; dubious source code comment / inverted if condition? https://svn.boost.org/trac10/ticket/10985 <p> Static code analysis with Coverity pointed me to some dead code in the function ibeta_imp in boost/math/special_functions/beta.hpp. My system's boost library is 1.55.0, but the issue is present identically in boost 1.57. In a block guarded by </p> <pre class="wiki">if (normalised) { </pre><p> there is the following line (number 1224): </p> <pre class="wiki"> fract -= (normalised ? 1 : boost::math::beta(a, b, pol)); </pre><p> Clearly, normalised has to be true due to the if guard thus the second part (boost::math::beta(a, b, pos)) will never be used. </p> <p> Furthermore, it may be that the if guard's condition is missing a negation for which there are two indications: </p> <ul><li>in the vicinity (i.e. in the function ibeta_imp) most other if statements (6 of 7) that involve normalised check if normalised is not set (i.e. "if(!normalised)"), and </li><li>more importantly, the first comment in that block on lines 1211-1213 reads: <pre class="wiki">1209: else if(normalised) 1210: { 1211: // the formula here for the non-normalised case is tricky to figure 1212: // out (for me!!), and requires two pochhammer calculations rather 1213: // than one, so leave it for now.... </pre></li></ul><p> I apologize for my limited understanding of the details of the code, which precludes me from proposing a fix, but something seems fishy here! </p> <p> Finally, the line subsequent to the one with the dead code, i.e. line 1225, contains a commented-out alternative. This indicates to me that this entire block may not have been fully satisfactory to the original author(s). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10985 Trac 1.4.3 John Maddock Thu, 05 Feb 2015 18:43:04 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10985#comment:1 https://svn.boost.org/trac10/ticket/10985#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> Fixed in <a class="ext-link" href="https://github.com/boostorg/math/commit/20965d162e0b6ae6f3308bceb3bfc5f27d43b031"><span class="icon">​</span>https://github.com/boostorg/math/commit/20965d162e0b6ae6f3308bceb3bfc5f27d43b031</a> </p> <p> The logic in the branch is correct - I had originally intenbded this branch to handle both normalized and not cases, but couldn't get the non-normalized case working correctly so it got excluded without tidying up the now-dead code. </p> Ticket