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

Alex Herbert commented on NUMBERS-163:
--------------------------------------

{quote}Isn't this "FuseMultiplyAdd"?
{quote}
Not quite. LinearCombination computes the double length product of two 
arguments. The higher and lower parts of the 106-bit mantissa of the result. 
The high part is the standard product and the lower part is the bits lost 
during rounding. LinearCombination then sums the standard products and during 
this summation computes the round-off and sums them separately, along with the 
lower parts of each product. This is not exact.

For FMA the second addition argument has to be added to the lower part first, 
and the intermediate result added to the higher part. The bits lost to rounding 
in the first addition have to be carried forward to ensure exact rounding. The 
operation has to avoid intermediate overflow by using scaling:
{code:java}
double x = Double.MAX_VALUE;
double y = Math.fma(x, 2, -x);
assert x == y;
{code}
x should not be infinity.

All this means that FMA is a lot more complicated to implement than the 
summation performed in LinearCombination. The gain may be a single ULP of 
precision for the result, and overflow protection.

> 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