The result types in sumOfPrimitiveProcedure.stg need to be widened to prevent overflow
I discovered there is an overflow error using sumOfInt in the following code when the batch size exceeded 536
This code returned the correct sum:
long sum = Interval.oneTo(2_000_000)
.toList()
.asParallel(Executors.newSingleThreadExecutor(), 536)
.sumOfInt(each -> each * 2);
This code returned the incorrect sum:
long sum = Interval.oneTo(2_000_000)
.toList()
.asParallel(Executors.newSingleThreadExecutor(), 537)
.sumOfInt(each -> each * 2);
I tracked the problem down to SumOfIntProcedure returning int instead of long for the result. This Procedure must be used in the individual batches and if a batch gets large enough with large values being summed, overflow is occurring.
https://github.com/eclipse/eclipse-collections/blob/master/eclipse-collections-code-generator/src/main/resources/impl/block/procedure/sumOfPrimitiveProcedure.stg#L33
Hi, I would like to take up this issue. Could you assign it to me? Thank you!
Thanks for volunteering @rzrobin213 ! I have assigned the issue to you.
@donraab File eclipse-collections/src/main/java/org/eclipse/collections/impl/block/procedure/SumOfIntProcedure.java seems not to be auto-generated. OTOH, file eclipse-collections/target/generated-sources/java/org/eclipse/collections/impl/block/procedure/SumOfByteProcedure.java says that it is generated from the sumOfPrimitiveProcedure.stg.
Hi! Could you assign this issue to me, since rzrobin123 do not seem to be working on this.
hello!! I have made a pull request regarding this issue..please review it. @donraab