Code review request: 6282196 There should be Math.mod(number, modulo) methods

Stephen Colebourne scolebourne at
Wed Feb 22 14:37:42 UTC 2012

Can you explain why the mod implementation differs from that in JSR-310?

The code ((a % b) + b) % b;  is short and involves no branches, which
should aid performance and inlining. Is this to do with accepting a
negative second argument? Perofmance testing?

I'd like to see performance numbers comparing the two approaches, as
JSR-310 might need to continue using the double % version if it is

Similarly, the proposed floorDiv requires evaluation of the complex if
statement every time, whereas the JSR-310 one only requires an if
check against zero. Whats the rationale for the difference, which is
intuitively (non-proven) slower.


On 22 February 2012 14:24, Roger Riggs <Roger.Riggs at> wrote:
> Hi,
> 6282196 There should be Math.mod(number, modulo) methods
> <>
> Requests that floor and modulus methods be provided for primitive types.
> Floor division is pretty straight-forward, rounding toward minus infinity.
> For modulus of int and long, the sign and range follow  the exiting floor
> method
> in java.util.Math and satisfy the relation that mod(x, y) = (x - floorDiv(x,
> y) * y).
> Please review and comment,
> Thanks, Roger

More information about the core-libs-dev mailing list