Modulo

I agree with jwatte. Or is your method in any way better?

The question is about the behavior for negative arguments.

need a check on divide by zero also

dont advise using exceptions as logic flow - they are exceptions…