1. ## Modulus Division?

Good evening!

I am doing some homework. As part of the solution, I want to implement an algorithm that implements modulus division. I was wondering if C had an operator which does just that?
I know of the % operator, which gives you the remainder of two numbers ( 27 % 7 = 6) and that works fine 99% of the time. The only part where it fails is when I get into negative numbers. If I do - 3 % 9 in C, the answer returns -3, which makes sense as the remainder in -2. However in modulus division the answer would be 6 (modulus division considers - 3 mod 9 as -1 + (6/9), hence the answer is 6). Is there an operator that would do this sort of operation?

I know in either VB or C# you had the "mod" reserved word which would do that nicely. A similar one exist in C?

Thanks!

2. You could probably write your own wrapper function to detect negative parameters, and then do "the right thing".

One more thing, % on negative numbers has implementation-specific behaviour in C.

3. Originally Posted by Shamshir
If I do - 3 % 9 in C, the answer returns -3, which makes sense as the remainder in -2. However in modulus division the answer would be 6 (modulus division considers - 3 mod 9 as -1 + (6/9), hence the answer is 6).
What? Why on earth would you expect to get -2 for the remainder?
Originally Posted by Shamshir
Is there an operator that would do this sort of operation?
You mean an operator that would give you the completely wrong answer? Why would you want that?

Quzah.

4. Originally Posted by quzah
What? Why on earth would you expect to get -2 for the remainder?You mean an operator that would give you the completely wrong answer? Why would you want that?

Quzah.
Woah relax, it was just a typo. So -3 is the remainder.

Originally Posted by Salem
You could probably write your own wrapper function to detect negative parameters, and then do "the right thing".

One more thing, % on negative numbers has implementation-specific behaviour in C.
Yeah, I was thinking along those lines, just was wondering if a reserved word/operator existed which would save me the trouble. But alas, here's to more lines of code!