Man Linux: Main Page and Category List

ggidev-add_3,ggidev-sub_3,ggidev-mul_3,ggidev-divmod_3- Binary arithmetic triple-int operations

#include <ggi/internal/triple-int.h> unsigned *add_3(unsigned l[3], unsigned r[3]); unsigned *sub_3(unsigned l[3], unsigned r[3]); unsigned *mul_3(unsigned l[3], unsigned r[3]); unsigned *divmod_3(unsigned a[3], unsigned b[3], unsigned q[3], unsigned r[3]);

add_3addsrtol. Equivalent to l+=r.sub_3subtractsrfroml. Equivalent to l-=r.mul_3multipliesrwithl. Equivalent to l*=r.divmod_3calculates the quotientqand the remainderrofa/bsuch thata=q*b+r. Equivalent to r=a%b,q=a/b. Multiplication and division needs to operate onlimbsto perform long multiplication and division. If a type with twice the precision of anunsignedis found (typically thelonglongtype),unsignedis used as thelimb. If not, half the bits of anunsignedare used as thelimb. 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.

add_3,sub_3andmul_3all return a pointer tolwhich has been updated in place. divmod_3 returns a pointer to the quotientq.

Some binary arithmetic operations ontriple-ints: unsigned x[3], y[3], q[3], r[3]; 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 */

triple-int(7), assign_int_3(3)