Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#8262 closed Bugs (fixed)

numeric::average gives incorrect result

Reported by: james.hirschorn@… Owned by: Eric Niebler
Milestone: To Be Determined Component: accumulator
Version: Boost 1.53.0 Severity: Problem
Keywords: average Cc:

Description

Apparently boost::numeric::average was incorrectly implemented as numeric::divides.

The following code, computes average(2, 3) = 0.666667:

#include <iostream>
#include <boost/accumulators/numeric/functional.hpp>

int main(int argc, char * argv[])
{
    using namespace boost::numeric;

    auto avg = average(2, 3);

    std::cout << avg << std::endl;
}

Attachments (2)

functional.hpp (21.9 KB ) - added by james.hirschorn@… 10 years ago.
patch giving correct average
average_fix.patch (1.1 KB ) - added by james.hirschorn@… 10 years ago.
patch correcting numeric::average

Download all attachments as: .zip

Change History (9)

by james.hirschorn@…, 10 years ago

Attachment: functional.hpp added

patch giving correct average

by james.hirschorn@…, 10 years ago

Attachment: average_fix.patch added

patch correcting numeric::average

comment:1 by james.hirschorn@…, 10 years ago

The first attachment was by accident. functional.hpp is the modified source.

comment:2 by Eric Niebler, 9 years ago

Resolution: invalid
Status: newclosed

Looks right to me.

comment:3 by Eric Niebler, 9 years ago

Resolution: invalid
Status: closedreopened

Oops, I see what you mean. Sory 'bout that. I'll have a look.

comment:4 by Eric Niebler, 9 years ago

(In [85124]) rename average to fdiv, refs #8262

comment:5 by Eric Niebler, 9 years ago

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.

comment:6 by Eric Niebler, 9 years ago

Resolution: fixed
Status: reopenedclosed

(In [85424]) merge [85122],[85123],[85124] from trunk to release; fixes #7915, fixes #8850, fixes #8262

comment:7 by timpie.w@…, 8 years ago

The fix seems incorrect.

typedef typename functional::divides<Left, Right>::result_type result_type;

looks incorrect and I think it should be

typedef typename functional::divides<

typename functional::plus<Left, Right>::result_type, int>::result_type result_type;

Note: See TracTickets for help on using tickets.