[BACK]Return to bf.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / engine

Annotation of OpenXM_contrib2/asir2000/engine/bf.c, Revision 1.5

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.5     ! ohara      48:  * $OpenXM: OpenXM_contrib2/asir2000/engine/bf.c,v 1.4 2003/02/14 22:29:08 ohara 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: void ritopa(Obj,GEN *);
                     57: void patori(GEN,Obj *);
                     58:
                     59: void addbf(a,b,c)
                     60: Num a,b;
                     61: Num *c;
                     62: {
                     63:        GEN pa,pb,z;
                     64:        long ltop,lbot;
                     65:
                     66:        if ( !a )
                     67:                *c = b;
                     68:        else if ( !b )
                     69:                *c = a;
                     70:        else if ( (NID(a) <= N_A) && (NID(b) <= N_A ) )
                     71:                (*addnumt[MIN(NID(a),NID(b))])(a,b,c);
                     72:        else {
                     73:                ltop = avma; ritopa((Obj)a,&pa);
                     74:                ritopa((Obj)b,&pb); lbot = avma;
                     75:                z = gerepile(ltop,lbot,gadd(pa,pb));
                     76:                patori(z,(Obj *)c); cgiv(z);
                     77:        }
                     78: }
                     79:
                     80: void subbf(a,b,c)
                     81: Num a,b;
                     82: Num *c;
                     83: {
                     84:        GEN pa,pb,z;
                     85:        long ltop,lbot;
                     86:
                     87:        if ( !a )
                     88:                (*chsgnnumt[NID(b)])(b,c);
                     89:        else if ( !b )
                     90:                *c = a;
                     91:        else if ( (NID(a) <= N_A) && (NID(b) <= N_A ) )
                     92:                (*subnumt[MIN(NID(a),NID(b))])(a,b,c);
                     93:        else {
                     94:                ltop = avma; ritopa((Obj)a,&pa); ritopa((Obj)b,&pb); lbot = avma;
                     95:                z = gerepile(ltop,lbot,gsub(pa,pb));
                     96:                patori(z,(Obj *)c); cgiv(z);
                     97:        }
                     98: }
                     99:
                    100: void mulbf(a,b,c)
                    101: Num a,b;
                    102: Num *c;
                    103: {
                    104:        GEN pa,pb,z;
                    105:        long ltop,lbot;
                    106:
                    107:        if ( !a || !b )
                    108:                *c = 0;
                    109:        else if ( (NID(a) <= N_A) && (NID(b) <= N_A ) )
                    110:                (*mulnumt[MIN(NID(a),NID(b))])(a,b,c);
                    111:        else {
                    112:                ltop = avma; ritopa((Obj)a,&pa); ritopa((Obj)b,&pb); lbot = avma;
                    113:                z = gerepile(ltop,lbot,gmul(pa,pb));
                    114:                patori(z,(Obj *)c); cgiv(z);
                    115:        }
                    116: }
                    117:
                    118: void divbf(a,b,c)
                    119: Num a,b;
                    120: Num *c;
                    121: {
                    122:        GEN pa,pb,z;
                    123:        long ltop,lbot;
                    124:
                    125:        if ( !b )
                    126:                error("divbf : division by 0");
                    127:        else if ( !a )
                    128:                *c = 0;
                    129:        else if ( (NID(a) <= N_A) && (NID(b) <= N_A ) )
                    130:                (*divnumt[MIN(NID(a),NID(b))])(a,b,c);
                    131:        else {
                    132:                ltop = avma; ritopa((Obj)a,&pa); ritopa((Obj)b,&pb); lbot = avma;
                    133:                z = gerepile(ltop,lbot,gdiv(pa,pb));
                    134:                patori(z,(Obj *)c); cgiv(z);
                    135:        }
                    136: }
                    137:
                    138: void pwrbf(a,e,c)
                    139: Num a,e;
                    140: Num *c;
                    141: {
                    142:        if ( !e )
                    143:                *c = (Num)ONE;
                    144:        else if ( !a )
                    145:                *c = 0;
                    146:        else {
1.5     ! ohara     147:                gpui_ri((Obj)a,(Obj)c,(Obj *)c);
1.1       noro      148:        }
                    149: }
                    150:
                    151: void chsgnbf(a,c)
                    152: Num a,*c;
                    153: {
                    154:        BF t;
                    155:        GEN z;
                    156:        int s;
                    157:
                    158:        if ( !a )
                    159:                *c = 0;
                    160:        else if ( NID(a) <= N_A )
                    161:                (*chsgnnumt[NID(a)])(a,c);
                    162:        else {
                    163:                z = (GEN)((BF)a)->body; s = lg(z); NEWBF(t,s);
                    164:                bcopy((char *)a,(char *)t,sizeof(struct oBF)+((s-1)*sizeof(long)));
                    165:                z = (GEN)((BF)t)->body; setsigne(z,-signe(z));
                    166:                *c = (Num)t;
                    167:        }
                    168: }
                    169:
                    170: int cmpbf(a,b)
                    171: Num a,b;
                    172: {
                    173:        GEN pa,pb;
                    174:        int s;
                    175:
                    176:        if ( !a ) {
                    177:                if ( !b || (NID(b)<=N_A) )
                    178:                        return (*cmpnumt[NID(b)])(a,b);
                    179:                else
                    180:                        return -signe(((BF)b)->body);
                    181:        } else if ( !b ) {
                    182:                if ( !a || (NID(a)<=N_A) )
                    183:                        return (*cmpnumt[NID(a)])(a,b);
                    184:                else
                    185:                        return signe(((BF)a)->body);
                    186:        } else {
                    187:                ritopa((Obj)a,&pa); ritopa((Obj)b,&pb);
                    188:                s = gcmp(pa,pb); cgiv(pb); cgiv(pa);
                    189:                return s;
                    190:        }
                    191: }
                    192: #endif /* PARI */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>