RFR 8005311: Add Scalable Updatable Variables, DoubleAccumulator, DoubleAdder, LongAccumulator, LongAdder
Peter Levart
peter.levart at gmail.com
Tue Jan 8 15:05:48 UTC 2013
On 01/08/2013 03:38 PM, Peter Levart wrote:
> On 01/07/2013 08:07 PM, Joe Darcy wrote:
>> Hello,
>>
>> I had a question about how the double accumulation logic was intended
>> to be used. I've taken a quick look at the code and it uses
>> straightforward "sum = sum + nextValue" code to compute the double
>> sum. Summing doubles values with code numerical accuracy is
>> surprisingly tricky and if the DoubleAccumulator code is meant for
>> wide use, I'd recommend using instead some form of compensated
>> summation:
>>
>> http://en.wikipedia.org/wiki/Kahan_summation_algorithm
>
> Hello Joe,
>
> It's very hard to program such algorithm in Java. Guess what prints
> the following code:
>
> double x = 1.0E100;
> double a = 1d;
> double y = x + a;
> double diff = y - x;
> double c = a - diff;
> System.out.println(diff);
> System.out.println(c);
>
> Do you have any idea how to do that (still using local variables)?
>
> Regards, Peter
Disregard this question. I thought I saw it reversed...
Regards, Peter
>
>
>>
>> Thanks,
>>
>> -Joe
>>
>> On 1/5/2013 10:10 AM, Chris Hegarty wrote:
>>> As part of JEP 155 we are proposing to add the following public
>>> classes to support Scalable Updatable Variables, DoubleAccumulator,
>>> DoubleAdder, LongAccumulator and LongAdder.
>>>
>>> These have been written by Doug Lea, with assistance from members of
>>> the former JCP JSR-166 Expert Group.
>>>
>>> Webrev and javadoc are at:
>>> http://cr.openjdk.java.net/~chegar/8005311/ver.00/
>>>
>>> Since Doug is the author, I am taking a reviewer/sponsor role.
>>>
>>> Here are my initial comments.
>>> - There are various places in DoubleAccmulator where there are broken
>>> links to #sum ( I think it is just a cut'n'paste error ). These
>>> should be #get.
>>> - Accumulators
>>> {@link #get} may read somewhat better as {@link #get current
>>> value} ??
>>> - Accumulators
>>> Does the 'identity' value need further explanation?
>>>
>>> Note: There is one minor change to the implementation. Currently in
>>> the jdk8 repo j.u.f.DoubleBinaryOperator defines operateAsDouble.
>>> This method has been renamed to applyAsDouble in the lambda/lambda
>>> repo. When these changes are sync'ed from lambda/lambda this can be
>>> reverted. A similar comment has been added to the code.
>>>
>>> -Chris.
>>
>
More information about the core-libs-dev
mailing list