|
|
1.1 root 1: #include "mprec.h"
2:
3:
4: /*
5: * Mult multiplies the mint pointed to by "a" by that pointed to
6: * by "b" and places the result in "c". Note that no assumption
7: * is made as to "a", "b" and "c" all being different.
8: */
9:
10: void
11: mult(a, b, c)
12: register mint *a, *b;
13: mint *c;
14: {
15: mint res, al;
16: int apos; /* a-is-positive flag */
17: char *ap;
18: register unsigned count;
19:
20: /* make sure that b is at least as long as a */
21: if (a->len > b->len) {
22: register mint *temp;
23:
24: temp = a;
25: a = b;
26: b = temp;
27: }
28:
29: /* replace a by abs. value */
30: apos = ispos(a);
31: if (!apos) {
32: minit(&al);
33: mneg(a, &al);
34: a = &al;
35: }
36:
37: /* if a is one byte, use smult */
38: if (a->len == 1) {
39: smult(b, *a->val, c);
40: if (!apos) {
41: mneg(c, c);
42: mpfree(al.val);
43: }
44: return;
45: }
46:
47: /* allocate result and zero it out */
48: res.len = a->len + b->len;
49: res.val = (char *)mpalc(res.len);
50: count = res.len;
51: {
52: register char *ap;
53:
54: ap = res.val;
55: while (count-- != 0)
56: *ap++ = 0;
57: }
58:
59: /* form partial products and total in res */
60: count = a->len;
61: ap = a->val + a->len;
62: while (count-- != 0) {
63: msma(b, *--ap, count, &res);
64: }
65: norm(&res);
66:
67: /* if needed, negate result and throw away negated a */
68: if (!apos) {
69: mpfree(al.val);
70: mneg(&res, &res);
71: }
72:
73: /* replace old c value by new one */
74: mpfree(c->val);
75: *c = res;
76: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.