Modify

Opened 4 years ago

Closed 4 years ago

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

Download all attachments as: .zip

Change History (9)

Changed 4 years ago by james.hirschorn@…

patch giving correct average

Changed 4 years ago by james.hirschorn@…

patch correcting numeric::average

comment:1 Changed 4 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 set to invalid
  • Status changed from new to closed

Looks right to me.

comment:3 Changed 4 years ago by eric_niebler

  • Resolution invalid deleted
  • Status changed from closed to reopened

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 set to fixed
  • Status changed from reopened to closed

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

comment:7 Changed 3 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;

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain eric_niebler.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.