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
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.