Modify

Opened 5 years ago

Closed 4 years ago

Last modified 4 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@… 5 years ago.
patch giving correct average
average_fix.patch (1.1 KB) - added by james.hirschorn@… 5 years ago.
patch correcting numeric::average

Download all attachments as: .zip

Change History (9)

Changed 5 years ago by james.hirschorn@…

Attachment: functional.hpp added

patch giving correct average

Changed 5 years ago by james.hirschorn@…

Attachment: average_fix.patch added

patch correcting numeric::average

comment:1 Changed 5 years ago by james.hirschorn@…

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

comment:2 Changed 4 years ago by Eric Niebler

Resolution: invalid
Status: newclosed

Looks right to me.

comment:3 Changed 4 years ago by Eric Niebler

Resolution: invalid
Status: closedreopened

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

comment:4 Changed 4 years ago by Eric Niebler

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

comment:5 Changed 4 years ago by Eric Niebler

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 Changed 4 years ago by Eric Niebler

Resolution: fixed
Status: reopenedclosed

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

comment:7 Changed 4 years ago by timpie.w@…

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;

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Eric Niebler.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.