Boost C++ Libraries: Ticket #8262: numeric::average gives incorrect result https://svn.boost.org/trac10/ticket/8262 <p> Apparently boost::numeric::average was incorrectly implemented as numeric::divides. </p> <p> The following code, computes average(2, 3) = 0.666667: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/accumulators/numeric/functional.hpp&gt; int main(int argc, char * argv[]) { using namespace boost::numeric; auto avg = average(2, 3); std::cout &lt;&lt; avg &lt;&lt; std::endl; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8262 Trac 1.4.3 james.hirschorn@… Thu, 07 Mar 2013 23:30:38 GMT attachment set https://svn.boost.org/trac10/ticket/8262 https://svn.boost.org/trac10/ticket/8262 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">functional.hpp</span> </li> </ul> <p> patch giving correct average </p> Ticket james.hirschorn@… Thu, 07 Mar 2013 23:31:22 GMT attachment set https://svn.boost.org/trac10/ticket/8262 https://svn.boost.org/trac10/ticket/8262 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">average_fix.patch</span> </li> </ul> <p> patch correcting numeric::average </p> Ticket james.hirschorn@… Thu, 07 Mar 2013 23:33:07 GMT <link>https://svn.boost.org/trac10/ticket/8262#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8262#comment:1</guid> <description> <p> The first attachment was by accident. functional.hpp is the modified source. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Eric Niebler</dc:creator> <pubDate>Sat, 08 Jun 2013 21:03:30 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8262#comment:2 https://svn.boost.org/trac10/ticket/8262#comment:2 <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">invalid</span> </li> </ul> <p> Looks right to me. </p> Ticket Eric Niebler Sat, 08 Jun 2013 21:04:46 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/8262#comment:3 https://svn.boost.org/trac10/ticket/8262#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> <p> Oops, I see what you mean. Sory 'bout that. I'll have a look. </p> Ticket Eric Niebler Tue, 23 Jul 2013 06:28:56 GMT <link>https://svn.boost.org/trac10/ticket/8262#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8262#comment:4</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/85124" title="rename average to fdiv, refs #8262">[85124]</a>) rename average to fdiv, refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8262" title="#8262: Bugs: numeric::average gives incorrect result (closed: fixed)">#8262</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Eric Niebler</dc:creator> <pubDate>Tue, 23 Jul 2013 06:31:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8262#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8262#comment:5</guid> <description> <p> Fixed on trunk. I'll merge to release after tests have cycled. The function isn't incorrect per se; it's just very, very badly named. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Eric Niebler</dc:creator> <pubDate>Thu, 22 Aug 2013 19:39:57 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8262#comment:6 https://svn.boost.org/trac10/ticket/8262#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</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/85424" title="merge [85122],[85123],[85124] from trunk to release; fixes #7915, ...">[85424]</a>) merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/85122" title="fix msvc warning, refs #8850">[85122]</a>,<a class="changeset" href="https://svn.boost.org/trac10/changeset/85123" title="silly typos, refs #7915">[85123]</a>,<a class="changeset" href="https://svn.boost.org/trac10/changeset/85124" title="rename average to fdiv, refs #8262">[85124]</a> from trunk to release; fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7915" title="#7915: Patches: Minor doc typo in libs/accumulators/doc/accumulators.qbk (closed: fixed)">#7915</a>, fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8850" title="#8850: Patches: Patch for spurious warning at ... (closed: fixed)">#8850</a>, fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8262" title="#8262: Bugs: numeric::average gives incorrect result (closed: fixed)">#8262</a> </p> Ticket timpie.w@… Mon, 12 May 2014 12:01:48 GMT <link>https://svn.boost.org/trac10/ticket/8262#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8262#comment:7</guid> <description> <p> The fix seems incorrect. </p> <blockquote> <p> typedef typename functional::divides&lt;Left, Right&gt;::result_type result_type; </p> </blockquote> <p> looks incorrect and I think it should be </p> <blockquote> <p> typedef typename functional::divides&lt; </p> <blockquote> <p> typename functional::plus&lt;Left, Right&gt;::result_type, int&gt;::result_type result_type; </p> </blockquote> </blockquote> </description> <category>Ticket</category> </item> </channel> </rss>