=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/builtin/pf.c,v retrieving revision 1.22 retrieving revision 1.24 diff -u -p -r1.22 -r1.24 --- OpenXM_contrib2/asir2000/builtin/pf.c 2015/08/14 13:51:54 1.22 +++ OpenXM_contrib2/asir2000/builtin/pf.c 2018/03/28 05:27:22 1.24 @@ -45,7 +45,7 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/builtin/pf.c,v 1.21 2015/08/06 10:01:52 fujimoto Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/builtin/pf.c,v 1.23 2018/03/27 06:29:19 noro Exp $ */ #include "ca.h" #include "math.h" @@ -54,7 +54,7 @@ #include #endif -double const_pi(),const_e(); +double const_pi(),const_e(), double_factorial(); void make_ihyp(void); void make_hyp(void); @@ -94,8 +94,8 @@ int mp_pi(),mp_e(); int mp_exp(), mp_log(), mp_pow(); int mp_sin(),mp_cos(),mp_tan(),mp_asin(),mp_acos(),mp_atan(); int mp_sinh(),mp_cosh(),mp_tanh(),mp_asinh(),mp_acosh(),mp_atanh(); +int mp_factorial(),mp_abs(); - static V *uarg,*darg; static P x,y; static PF pidef,edef; @@ -104,13 +104,21 @@ static PF sindef,cosdef,tandef; static PF asindef,acosdef,atandef; static PF sinhdef,coshdef,tanhdef; static PF asinhdef,acoshdef,atanhdef; +static PF factorialdef,absdef; #define OALLOC(p,n) ((p)=(Obj *)CALLOC((n),sizeof(Obj))) double const_pi() { return 3.14159265358979323846264338327950288; } double const_e() { return 2.718281828459045235360287471352662497; } +double double_factorial(double x) +{ + return tgamma(x+1); +} + int simplify_elemfunc_ins(); +int simplify_factorial_ins(); +int simplify_abs_ins(); void pf_init() { uarg = (V *)CALLOC(1,sizeof(V)); @@ -120,9 +128,12 @@ void pf_init() { darg[0] = &oVAR[26]; darg[1] = &oVAR[27]; MKV(darg[1],y); - mkpf("@pi",0,0,0,(int (*)())mp_pi,const_pi,0,&pidef); - mkpf("@e",0,0,0,(int (*)())mp_e,const_e,0,&edef); + mkpf("@pi",0,0,0,(int (*)())mp_pi,const_pi,simplify_elemfunc_ins,&pidef); + mkpf("@e",0,0,0,(int (*)())mp_e,const_e,simplify_elemfunc_ins,&edef); + mkpf("factorial",0,1,uarg,(int (*)())mp_factorial,double_factorial,simplify_factorial_ins,&factorialdef); + mkpf("abs",0,1,uarg,(int (*)())mp_abs,fabs,simplify_abs_ins,&absdef); + mkpf("log",0,1,uarg,(int (*)())mp_log,log,simplify_elemfunc_ins,&logdef); mkpf("exp",0,1,uarg,(int (*)())mp_exp,exp,simplify_elemfunc_ins,&expdef); mkpf("pow",0,2,darg,(int (*)())mp_pow,pow,(int (*)())simplify_pow,&powdef); @@ -276,6 +287,8 @@ Obj *r; simplify_ins(ins,r); } +extern int evalef; + void simplify_pow(ins,rp) PFINS ins; Obj *rp; @@ -286,6 +299,10 @@ Obj *rp; V v; P t; + if ( evalef ) { + simplify_elemfunc_ins(ins,rp); + return; + } pf = ins->pf; ad = ins->ad; a0 = ad[0].arg; a1 = ad[1].arg; if ( !a1 ) *rp = (Obj)ONE; @@ -295,12 +312,12 @@ Obj *rp; else if ( RATN(a1) && SGN((Q)a1) < 0 ) error("simplify_pow : division by 0"); else { - instov(ins,&v); MKV(v,t); *rp = (Obj)t; + instoobj(ins,rp); } } else if ( NUM(a1) && INT(a1) ) arf_pwr(CO,a0,a1,rp); else { - instov(ins,&v); MKV(v,t); *rp = (Obj)t; + instoobj(ins,rp); } }