Negative integer modulo/division
Stewart Gordon
smjg_1998 at yahoo.com
Wed Mar 14 05:35:54 PDT 2012
On 14/03/2012 11:27, Steven Schveighoffer wrote:
<snip>
> This might be more efficient (assuming z is your target for this):
>
> if((z = x % y) < 0) z += y;
<snip>
Depends on what you want it to do if y is negative. In such cases, what you've got here
will return a value in (y, 0] if x is positive, or in (2*y, y] if x is negative.
I too wish D gave the choice between floor-mod and trunc-mod.
Stewart.
More information about the Digitalmars-d
mailing list