On 29 September 2015 at 16:02, Brian Burkhalter
<brian.burkhal...@oracle.com> wrote:
> 2)
> My preferred algorithm for floorMod is:
>
> return ((a % b) + b) % b;
>
> as it contains no Java-side branches, although tests would be needed
> to prove performance.
>
> This also allows an algorithm for floorDiv with no Java-side branches:
>
> int mod = ((a % b) + b) % b;
> return (a - mod) / b;
>
>
> I tested the code which was in the original issue description and found some
> discrepancies. I’ll need to revisit this to see what happened.

Yes, the code in the issue for floorDiv() fails when the divisor is
negative. The one in my email today works though.
Stephen

Reply via email to