Annotation of OpenXM_contrib2/asir2000/engine/QM.c, Revision 1.1.1.1
1.1 noro 1: /* $OpenXM: OpenXM/src/asir99/engine/QM.c,v 1.1.1.1 1999/11/10 08:12:26 noro Exp $ */
2: #include "ca.h"
3:
4: void addmq(m,n1,n2,nr)
5: int m;
6: MQ n1,n2,*nr;
7: {
8: int a;
9:
10: if ( !n1 )
11: *nr = n2;
12: else if ( !n2 )
13: *nr = n1;
14: else {
15: a = (CONT(n1) + CONT(n2)) % m; STOMQ(a,*nr);
16: }
17: }
18:
19: void submq(m,n1,n2,nr)
20: int m;
21: MQ n1,n2,*nr;
22: {
23: int a;
24:
25: if ( !n1 ) {
26: a = (m - CONT(n2)) % m; STOMQ(a,*nr);
27: } else if ( !n2 )
28: *nr = n1;
29: else {
30: a = (CONT(n1) - CONT(n2) + m) % m; STOMQ(a,*nr);
31: }
32: }
33:
34: void mulmq(m,n1,n2,nr)
35: int m;
36: MQ n1,n2,*nr;
37: {
38: int a,b;
39:
40: if ( !n1 || !n2 )
41: *nr = 0;
42: else {
43: a = dmb(m,CONT(n1),CONT(n2),&b); STOMQ(a,*nr);
44: }
45: }
46:
47: void divmq(m,n1,n2,nq)
48: int m;
49: MQ n1,n2,*nq;
50: {
51: int a,b;
52:
53: if ( !n2 )
54: error("divmq : division by 0");
55: else if ( !n1 )
56: *nq = 0;
57: else if ( n1 == n2 )
58: *nq = ONEM;
59: else {
60: a = dmb(m,CONT(n1),invm(CONT(n2),m),&b); STOMQ(a,*nq);
61: }
62: }
63:
64: void invmq(m,n1,nq)
65: int m;
66: MQ n1,*nq;
67: {
68: int a;
69:
70: if ( !n1 )
71: error("invmq : division by 0");
72: else {
73: a = invm(CONT(n1),m); STOMQ(a,*nq);
74: }
75: }
76:
77: void pwrmq(m,n1,n,nr)
78: int m;
79: MQ n1;
80: Q n;
81: MQ *nr;
82: {
83: int a;
84:
85: if ( n == 0 )
86: *nr = ONEM;
87: else if ( !n1 )
88: *nr = 0;
89: else {
90: a = pwrm(m,CONT(n1),QTOS(n)); STOMQ(a,*nr);
91: }
92: }
93:
94: void mkbcm(m,n,t)
95: int m,n;
96: MQ *t;
97: {
98: int i,j;
99: int *a,*b,*c;
100:
101: W_CALLOC(n,int,a); W_CALLOC(n,int,b);
102: for ( i = 1, a[0] = 1; i <= n; i++ ) {
103: for ( j = 1, b[0] = b[i] = 1; j < i; j++ )
104: b[j] = (a[j-1] + a[j]) % m;
105: c = a; a = b; b = c;
106: }
107: for ( i = 0; i <= n; i++ )
108: STOMQ(a[i],t[i]);
109: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>