[ 
https://issues.apache.org/jira/browse/NUMBERS-163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17362558#comment-17362558
 ] 

Matt Juntunen commented on NUMBERS-163:
---------------------------------------

No, it accumulates them. The basic structure should look like below. I have a 
specific idea for the API, I just haven't had time yet to write it.
{code:java}
static class Accumulator {
    private double sum;
    private double comp;
    
    public Accumulator add(double d) {
        double t = sum + d;
        comp += ExtendedPrecision.twoSumLow();        
        sum = t;
        
        return this;        
    }
    
    public double get() {
           return summationResult(sum, comp);
    }
}
{code}

> Summation and LinearCombination Accumulators
> --------------------------------------------
>
>                 Key: NUMBERS-163
>                 URL: https://issues.apache.org/jira/browse/NUMBERS-163
>             Project: Commons Numbers
>          Issue Type: New Feature
>            Reporter: Matt Juntunen
>            Priority: Major
>
> It would be useful to have simple accumulator classes in {{Summation}} and 
> {{LinearCombination}} to perform extended precision operations on arbitrary 
> collections of values without requiring conversion to {{double[]}}. Ex:
> {code:java}
> Summation.Accumulator sum= Summation.accumulator(1d);
> sum.add(x)
>     .add(y)
>     .add(z)
>    .add(w);
> double sumResult = sum.get();
> LinearCombination.Accumulator comb = LinearCombination.accumulator(1d);
> comb.add(x, scale)
>     .add(y, scale)
>     .add(z, scale)
>     .add(w, scale);
> double combResult = comb.get();
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to