hg: lambda/lambda/jdk: - implement IntStream.average (arithemtic mean).
Paul Sandoz
paul.sandoz at oracle.com
Tue Nov 20 08:46:56 PST 2012
On Nov 20, 2012, at 4:51 PM, Brian Goetz <brian.goetz at Oracle.COM> wrote:
> Rather than reduce with Integer::sum, should sum() use a reducing sink that internally does computation in long so as to be less sensitive to overflow when adding BIG + BIG + NEGATIVE_BIG?
>
I was wondering about whether IntStream.sum() should return long or not, and also what to do on overflows, i suppose one such answer would be for developers to do:
s.reduce(0, Math::addExact)
and catch the ArithmeticException.
Perhaps another solution is to widen the stream?
s.asLongs().sum()
Not as efficient though.
Paul.
> On 11/20/2012 10:34 AM, paul.sandoz at oracle.com wrote:
>> Changeset: 932b4939d7c8
>> Author: psandoz
>> Date: 2012-11-20 16:34 +0100
>> URL: http://hg.openjdk.java.net/lambda/lambda/jdk/rev/932b4939d7c8
>>
>> - implement IntStream.average (arithemtic mean).
>>
>> + src/share/classes/java/util/stream/primitive/IntAverageOp.java
>> ! src/share/classes/java/util/stream/primitive/IntPipeline.java
>> ! src/share/classes/java/util/stream/primitive/IntStream.java
>> + test-ng/tests/org/openjdk/tests/java/util/stream/primitive/IntAverageOpTest.java
>>
>>
More information about the lambda-dev
mailing list