http://www.digitalmars.com/d/archives/digitalmars/D/Could_we_have_mod_in_std.math_152977.html
On 14/03/2012 11:27, Steven Schveighoffer wrote:
This might be more efficient (assuming z is your target for this):
if((z = x % y) < 0) z += y;
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
On Tue, 13 Mar 2012 15:13:01 -0400, bearophile
wrote:
For the modulus I sometimes use:
((x % y) + y) % y
This might be more efficient (assuming z is your target for this):
if((z = x % y) < 0) z += y;
Though I don't know, maybe the optimizer will reduce to this.
Hard to do it in a single
When I translate Python code to D I sometimes need in D the different integer
division and the different modulo operation of Python3. They give different
results with the operands are negative:
Python2 code:
for x in xrange(-10, 1):
print x, "", x % 3, "", x // 3
Python output:
-10 2 -