Re: Possible long overflow in Collectors.averagingLong and LongStream.average

2015-08-15 Thread Tagir F. Valeev
Hello! Just for information: as finite stream size is very unlikely to exceed Long.MAX_VALUE (and even if exceeds it will take enormous CPU time to process such stream), the problem can be fixed just by tracking 128 bit sum instead of 64 bit. It's not very difficult to implement it: just two long

Possible long overflow in Collectors.averagingLong and LongStream.average

2015-08-12 Thread Tagir F. Valeev
Hello! The following code prints -1 twice, while users would normally expect something like 9.223372036854776E18: double avg1 = Stream.of(Long.MAX_VALUE, Long.MAX_VALUE).collect( Collectors.averagingLong(Long::valueOf)); System.out.println(avg1); double avg2 = LongStream.of(Long.