One should note that e-TeX's division rounds, so this method is not suitable to compute the remainder. This doesn't invalidate this solution, of course, as the difference between a multiple of 4 and a non-multiple of 4 can never be 0.
–
egregDec 19 '11 at 10:18

@egreg. Yes, and the LaTeX3 function \int_mod:nn uses some very clever code (by Heiko I believe) to work around that, while avoiding overflow in all cases.
–
Bruno Le FlochDec 19 '11 at 12:38

+1 because this is the only expandable answer so far (it is expandable, right?). But I have to say, I find the named macro argument syntax quite outlandish. :)
–
Bruno Le FlochDec 19 '11 at 5:02

@BrunoLeFloch: Yes, the code is expandable. As for the named arguments, one can also use #mod and #num; in fact, those are the recommended alternatives, but I prefer the #{...} variants.
–
AdityaDec 19 '11 at 6:09

just curious: with the #mod variant, how is the end of the argument name detects? Can you have delimited arguments that way?
–
Bruno Le FlochDec 19 '11 at 6:31

Isn't fp package (or, for that matter, any package) an overkill for this task? And is this fp solution expandable? fp solutions are hardly expandable. For non-context and non-lua users, I think Bruno's solution is more than enough, IMHO. And it's superfast. I often get scared by fp's trace log :)
–
Ahmed MusaDec 19 '11 at 16:46

2

@AhmedMusa: Sure, there are at least three other answers that produce a package-less solution. Honestly, speed for me is not an issue, since the time difference between fp's output and some other package-less output is most likely less than 0.1 seconds. I rely on code readability, which fp provides through its function shorthand/names. If I (or anyone for that matter) is relying on performing major calculations within TeX and want speed, they are perhaps better off using a different environment altogether. ;)
–
WernerDec 19 '11 at 16:54