Other Aliasggidev-add_3, ggidev-sub_3, ggidev-divmod_3
unsigned *add_3(unsigned l, unsigned r);
unsigned *sub_3(unsigned l, unsigned r);
unsigned *mul_3(unsigned l, unsigned r);
unsigned *divmod_3(unsigned a, unsigned b,
unsigned q, unsigned r);
DESCRIPTIONadd_3 adds r to l. Equivalent to l+=r.
sub_3 subtracts r from l. Equivalent to l-=r.
mul_3 multiplies r with l. Equivalent to l*=r.
divmod_3 calculates the quotient q and the remainder r of a/b such that a = q * b + r. Equivalent to r=a%b,q=a/b.
Multiplication and division needs to operate on limbs to perform long multiplication and division. If a type with twice the precision of an unsigned is found (typically the long long type), unsigned is used as the limb. If not, half the bits of an unsigned are used as the limb.
The division algorithm is probably similar to the algorithm described by Donald E. Knuth in "The Art of Computer Programming", volume 2, but the author of the code has not actually read that book, only a short description of the algorithm. The degree of similarity is therefore uncertain.
RETURN VALUEadd_3, sub_3 and mul_3 all return a pointer to l which has been updated in place.
divmod_3 returns a pointer to the quotient q.
EXAMPLESSome binary arithmetic operations on triple-ints:
unsigned x, y, q, r; assign_int_3(x, 4); assign_int_3(y, 5); add_3(x, y); /* x == 9 */ assign_int_3(q, 3); sub_3(x, q); /* x == 6 */ mul_3(x, q); /* x == 18 */ divmod_3(x, y, q, r); /* q == 3, r == 3 */