#8262 closed Bugs (fixed)
numeric::average gives incorrect result
| Reported by: | 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)
Change History (9)
by , 10 years ago
| Attachment: | functional.hpp added |
|---|
comment:1 by , 10 years ago
The first attachment was by accident. functional.hpp is the modified source.
comment:3 by , 9 years ago
| Resolution: | invalid |
|---|---|
| Status: | closed → reopened |
Oops, I see what you mean. Sory 'bout that. I'll have a look.
comment:5 by , 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 , 9 years ago
| Resolution: | → fixed |
|---|---|
| Status: | reopened → closed |
comment:7 by , 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;

patch giving correct average