note
JavaFan
Yeah, they are rounding errors. Rearranging the calculation fixes it (at least, on my platform):
<code>
sub ranges_javafan {
my ($M, $N) = @_;
return [ map {[int($_/$N*($M+1))
, int((($_+1)/$N)*($M+1))-1]
} 0..$N - 1];
}
</code>
The most important is the final <c>($_+1)/$N*($M+1)</c> - that should return <c>$M+1</c> for <c>$_ == $N-1</c>. The impact of other rounding errors is that a range is 1 shorter than expected (but making the next one one larger - it shouldn't skip numbers).
892828
892900