Annotation of OpenXM_contrib2/asir2000/engine/bf.c, Revision 1.4
1.2 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.4 ! ohara 48: * $OpenXM: OpenXM_contrib2/asir2000/engine/bf.c,v 1.3 2000/08/22 05:04:05 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
1.4 ! ohara 51: #if defined(PARI)
1.1 noro 52: #include "base.h"
53: #include <math.h>
54: #include "genpari.h"
55:
56: extern long prec;
57:
58: void ritopa(Obj,GEN *);
59: void patori(GEN,Obj *);
60:
61: void addbf(a,b,c)
62: Num a,b;
63: Num *c;
64: {
65: GEN pa,pb,z;
66: long ltop,lbot;
67:
68: if ( !a )
69: *c = b;
70: else if ( !b )
71: *c = a;
72: else if ( (NID(a) <= N_A) && (NID(b) <= N_A ) )
73: (*addnumt[MIN(NID(a),NID(b))])(a,b,c);
74: else {
75: ltop = avma; ritopa((Obj)a,&pa);
76: ritopa((Obj)b,&pb); lbot = avma;
77: z = gerepile(ltop,lbot,gadd(pa,pb));
78: patori(z,(Obj *)c); cgiv(z);
79: }
80: }
81:
82: void subbf(a,b,c)
83: Num a,b;
84: Num *c;
85: {
86: GEN pa,pb,z;
87: long ltop,lbot;
88:
89: if ( !a )
90: (*chsgnnumt[NID(b)])(b,c);
91: else if ( !b )
92: *c = a;
93: else if ( (NID(a) <= N_A) && (NID(b) <= N_A ) )
94: (*subnumt[MIN(NID(a),NID(b))])(a,b,c);
95: else {
96: ltop = avma; ritopa((Obj)a,&pa); ritopa((Obj)b,&pb); lbot = avma;
97: z = gerepile(ltop,lbot,gsub(pa,pb));
98: patori(z,(Obj *)c); cgiv(z);
99: }
100: }
101:
102: void mulbf(a,b,c)
103: Num a,b;
104: Num *c;
105: {
106: GEN pa,pb,z;
107: long ltop,lbot;
108:
109: if ( !a || !b )
110: *c = 0;
111: else if ( (NID(a) <= N_A) && (NID(b) <= N_A ) )
112: (*mulnumt[MIN(NID(a),NID(b))])(a,b,c);
113: else {
114: ltop = avma; ritopa((Obj)a,&pa); ritopa((Obj)b,&pb); lbot = avma;
115: z = gerepile(ltop,lbot,gmul(pa,pb));
116: patori(z,(Obj *)c); cgiv(z);
117: }
118: }
119:
120: void divbf(a,b,c)
121: Num a,b;
122: Num *c;
123: {
124: GEN pa,pb,z;
125: long ltop,lbot;
126:
127: if ( !b )
128: error("divbf : division by 0");
129: else if ( !a )
130: *c = 0;
131: else if ( (NID(a) <= N_A) && (NID(b) <= N_A ) )
132: (*divnumt[MIN(NID(a),NID(b))])(a,b,c);
133: else {
134: ltop = avma; ritopa((Obj)a,&pa); ritopa((Obj)b,&pb); lbot = avma;
135: z = gerepile(ltop,lbot,gdiv(pa,pb));
136: patori(z,(Obj *)c); cgiv(z);
137: }
138: }
139:
140: void pwrbf(a,e,c)
141: Num a,e;
142: Num *c;
143: {
144: GEN pa,pe,z;
145: long ltop,lbot;
146:
147: if ( !e )
148: *c = (Num)ONE;
149: else if ( !a )
150: *c = 0;
151: else {
152: ltop = avma; ritopa((Obj)a,&pa); ritopa((Obj)e,&pe); lbot = avma;
153: z = gerepile(ltop,lbot,gpui(pa,pe,prec));
154: patori(z,(Obj *)c); cgiv(z);
155: }
156: }
157:
158: void chsgnbf(a,c)
159: Num a,*c;
160: {
161: BF t;
162: GEN z;
163: int s;
164:
165: if ( !a )
166: *c = 0;
167: else if ( NID(a) <= N_A )
168: (*chsgnnumt[NID(a)])(a,c);
169: else {
170: z = (GEN)((BF)a)->body; s = lg(z); NEWBF(t,s);
171: bcopy((char *)a,(char *)t,sizeof(struct oBF)+((s-1)*sizeof(long)));
172: z = (GEN)((BF)t)->body; setsigne(z,-signe(z));
173: *c = (Num)t;
174: }
175: }
176:
177: int cmpbf(a,b)
178: Num a,b;
179: {
180: GEN pa,pb;
181: int s;
182:
183: if ( !a ) {
184: if ( !b || (NID(b)<=N_A) )
185: return (*cmpnumt[NID(b)])(a,b);
186: else
187: return -signe(((BF)b)->body);
188: } else if ( !b ) {
189: if ( !a || (NID(a)<=N_A) )
190: return (*cmpnumt[NID(a)])(a,b);
191: else
192: return signe(((BF)a)->body);
193: } else {
194: ritopa((Obj)a,&pa); ritopa((Obj)b,&pb);
195: s = gcmp(pa,pb); cgiv(pb); cgiv(pa);
196: return s;
197: }
198: }
199: #endif /* PARI */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>