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

Gilles Sadowski commented on NUMBERS-163:
-----------------------------------------

bq. FMA is a lot more complicated to implement than the summation performed in 
LinearCombination.

>From a design (API/implementation) POV, and following up on Matt's proposal, 
>could we provide a class that mimics FMA usage (even if not all its 
>requirements)?

{code}
public class FMA implements DoubleSupplier {
    // ... state?

    private FMA(double m1, double m2, double a) {
         // ...
    }

    public FMA.of(double m1, double m2, double a) {
         return new FMA(m1, m2, a);
    }

    public FMA.of(double m1, double m2, FMA other) {
         final double a = ...
         return new FMA(m1, m2, a);
    }

    // To allow usage in a collector.
    public FMA fma(FMA other) {
        // ... ?
    }

    @Override
    public double getAsDouble() {
        // The equivalent of Math.fma(m1, m2, a).
        return ...
    }
}
{code}

With the above API, is it possible to implement the combined functionality of 
{{LinearCombination}} and {{Summation}}, with the same accuracy?

>From a usage POV,
{code}
LinearCombination.of(a1, v1, a2, v2);
{code}
would be replaced with
{code}
FMA.of(a1, v1, FMA.of(a2, v2, 0));
{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
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> 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