in reply to Re: A better mod (%) operator?
in thread A better mod (%) operator?
you could do it with side effects on the arguments.
That kind of defeats the original purpose of utilising the fact that -- for every processor I'm knowledgeable of; though that's not a huge sample -- at the machine code level, DIV instructions produce both quotient and remainder as the result of a single operation.
From the Intel manual:
DIV—Unsigned Divide
Description: Divides unsigned the value in the AX, DX:AX, EDX:EAX, or RDX:RAX registers (divi- dend) by the source operand (divisor) and stores the result in the AX (AH:AL), DX:AX, EDX:EAX, or RDX:RAX registers.
The two operations of finding quotient and remainder of one number divided by another are so often used in concert with each other, it seems a waste to have to perform the division twice to get at both parts.
(Just for the fun of it in autoboxing notation...)
Yuck! What a waste of cpu :)