Boost logo

Boost :

Subject: Re: [boost] Interest in algorithm for arithmetic mean of integers
From: Bjorn Reese (breese_at_[hidden])
Date: 2015-09-05 07:07:19


On 09/04/2015 08:20 PM, Matt Calabrese wrote:

> At any given point, we have the whole number part, the numerator of the
> fractional part, and the denominator of the fractional part (remember that
> the denominator is guaranteed to always be the size of the range up to this
> point). When advancing to the next state, I do an operation that has the
> same effect as taking a single, rational version of the mixed number N/D,
> changing this value to N/(D+1), and then adding in V/(D+1), where V is the
> next value in the range (remember that here D is the current number of
> elements that we've iterated over). This isn't directly what I do since I'm
> dealing with a mixed number instead of a rational number, but it's the same
> overall effect and is done in a way that cannot overflow.

Can you provide an example of how it works? For example, if I have an
input array with {10, 20, 30}, how are V, N, and D updated in each
iteration?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk