|
|
1.1 root 1: #include "mprec.h"
2: #include <assert.h>
3:
4:
5: /*
6: * Msma takes the mint pointed to by "to" and adds to it (in place)
7: * the product of the following :
8: * 1. the mint pointed to by "from".
9: * 2. the int "fac" (it is assumed that 0 <= fac < 2 * BASE).
10: * 3. BASE raised to the "shift" power.
11: * Note that it is assumed that the length of "to" is big enough to
12: * hold the result.
13: * It is also assumed that "from" and "to" are distinct.
14: */
15:
16: void
17: msma(from, fac, shift, to)
18: mint *from, *to;
19: int fac;
20: unsigned shift;
21: {
22: register int carry;
23: register char *fp, *tp;
24: register unsigned count;
25: int mifl;
26:
27: assert(0 <= fac && fac < 2 * BASE);
28:
29: /* general case needs fac != 0, so handle fac == 0 */
30: if (fac == 0)
31: return;
32:
33: /* find out sign of "from" */
34: mifl = ispos(from);
35:
36: /* do the multiply assuming "from" is positive */
37: fp = from->val;
38: tp = to->val + shift;
39: carry = 0;
40: count = from->len;
41: if (!mifl)
42: --count;
43: assert(tp + count <= to->val + to->len);
44: while (count-- != 0) {
45: carry += *tp + *fp++ * fac;
46: *tp++ = carry % BASE;
47: carry >>= L2BASE;
48: }
49:
50: /* propogate carry or borrow */
51: count = to->val + to->len - tp;
52: if (!mifl)
53: carry -= fac;
54: while (count-- != 0 && carry != 0) {
55: carry += *tp + BASE;
56: *tp++ = carry % BASE;
57: carry = (carry >> L2BASE) - 1;
58: }
59: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.