IntStream.sum

Joe Darcy joe.darcy at oracle.com
Wed Jan 16 10:13:20 PST 2013


On 01/16/2013 09:59 AM, Kevin Bourrillion wrote:
> (making it just one line longer)

And one more line...

>
>
> On Wed, Jan 16, 2013 at 9:53 AM, Remi Forax <forax at univ-mlv.fr 
> <mailto:forax at univ-mlv.fr>> wrote:
>
>         I like the long return value, because the chance of 63-bit
>         overflow is so incredibly less likely than 31-bit overflow.
>
>
>     given that most people will cast the result to int, this argument
>     is moot.
>
>
> Not at all, because it's /their/ cast, in /their/ code, which, if they 
> are actually conscientious, /their/ static analysis tools and code 
> reviewers will challenge them over.
>
>

Summing in a long allows for the possibility of an intermediate overflow 
of int range with the final result coming back into int range.

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-experts/attachments/20130116/ac941432/attachment.html 


More information about the lambda-libs-spec-experts mailing list