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 expression without using a function. -Steve