version 1.21, 2015/08/07 06:15:00 |
version 1.25, 2015/08/17 05:18:36 |
|
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/builtin/parif.c,v 1.24 2015/08/16 03:12:09 noro Exp $ */ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
#include "ox.h" |
#include "ox.h" |
|
|
Q ox_pari_stream; |
Q ox_pari_stream; |
int ox_pari_stream_initialized = 0; |
int ox_pari_stream_initialized = 0; |
|
|
|
typedef void (*mpfr_func)(NODE,Obj *); |
|
|
|
void Pmpfr_ai(); |
|
void Pmpfr_eint(), Pmpfr_erf(),Pmpfr_li2(); |
|
void Pmpfr_zeta(); |
|
void Pmpfr_j0(), Pmpfr_j1(); |
|
void Pmpfr_y0(), Pmpfr_y1(); |
|
void Pmpfr_gamma(), Pmpfr_lngamma(), Pmpfr_digamma(); |
|
void Pmpfr_floor(), Pmpfr_round(), Pmpfr_ceil(); |
|
|
|
struct mpfr_tab_rec { |
|
char *name; |
|
mpfr_func func; |
|
} mpfr_tab[] = { |
|
{"ai",Pmpfr_ai}, |
|
{"zeta",Pmpfr_zeta}, |
|
{"j0",Pmpfr_j0}, |
|
{"j1",Pmpfr_j1}, |
|
{"y0",Pmpfr_y0}, |
|
{"y1",Pmpfr_y1}, |
|
{"eint",Pmpfr_eint}, |
|
{"erf",Pmpfr_erf}, |
|
{"li2",Pmpfr_li2}, |
|
{"gamma",Pmpfr_gamma}, |
|
{"lngamma",Pmpfr_gamma}, |
|
{"digamma",Pmpfr_gamma}, |
|
{"floor",Pmpfr_floor}, |
|
{"ceil",Pmpfr_ceil}, |
|
{"round",Pmpfr_round}, |
|
}; |
|
|
|
mpfr_func mpfr_search(char *name) |
|
{ |
|
int i,n; |
|
|
|
n = sizeof(mpfr_tab)/sizeof(struct mpfr_tab_rec); |
|
for ( i = 0; i < n; i++ ) |
|
if ( !strcmp(name,mpfr_tab[i].name) ) |
|
return mpfr_tab[i].func; |
|
return 0; |
|
} |
|
|
pointer evalparif(FUNC f,NODE arg) |
pointer evalparif(FUNC f,NODE arg) |
{ |
{ |
int ac,intarg,opt,prec; |
int ac,intarg,opt,prec; |
Q q,r,narg; |
Q q,r,narg; |
NODE nd,oxarg; |
NODE nd,oxarg,t,t1,n; |
STRING name; |
STRING name; |
USINT ui; |
USINT ui; |
Obj ret,dmy; |
Obj ret,dmy; |
|
mpfr_func mpfr_function; |
|
|
if (strcmp(f->name,"gamma")==0) { |
if ( mpfr_function = mpfr_search(f->name) ) { |
Pmpfr_gamma(arg,&ret); |
(*mpfr_function)(arg,&ret); |
return((pointer) ret); |
return (pointer) ret; |
}else if (strcmp(f->name,"floor")==0) { |
|
Pmpfr_floor(arg,&ret); |
|
return((pointer) ret); |
|
} |
} |
|
|
if ( !ox_pari_stream_initialized ) { |
if ( !ox_pari_stream_initialized ) { |
MKSTR(name,"ox_pari"); |
MKSTR(name,"ox_pari"); |
nd = mknode(2,NULL,name); |
nd = mknode(2,NULL,name); |
Pox_launch(nd,&r); |
Pox_launch_nox(nd,&r); |
ox_pari_stream = r; |
ox_pari_stream = r; |
ox_pari_stream_initialized = 1; |
ox_pari_stream_initialized = 1; |
} |
} |
switch ( f->type ) { |
|
case 0: /* in/out : integer */ |
|
ac = argc(arg); |
|
if ( ac > 1 ) { |
|
fprintf(stderr,"argument mismatch in %s()\n",NAME(f)); |
|
error(""); |
|
/* NOTREACHED */ |
|
return 0; |
|
} |
|
intarg = ac == 0 ? 0 : QTOS((Q)ARG0(arg)); |
|
MKUSINT(ui,intarg); |
|
oxarg = mknode(2,ox_pari_stream,ui); |
|
Pox_push_cmo(oxarg,&dmy); |
|
MKSTR(name,f->name); |
|
oxarg = mknode(3,ox_pari_stream,name,ONE); |
|
Pox_execute_function(oxarg,&dmy); |
|
oxarg = mknode(1,ox_pari_stream); |
|
Pox_pop_cmo(oxarg,&r); |
|
return r; |
|
|
|
case 1: |
ac = argc(arg); |
ac = argc(arg); |
/* reverse the arg list */ |
if ( !ac || ( ac > 2 ) ) { |
for ( n = arg, t = 0; n; n = NEXT(n) ) { |
fprintf(stderr,"argument mismatch in %s()\n",NAME(f)); |
MKNODE(t1,BDY(n),t); t = t1; |
error(""); |
} |
/* NOTREACHED */ |
/* push the reversed arg list */ |
return 0; |
for ( ; t; t = NEXT(t) ) { |
} |
oxarg = mknode(2,ox_pari_stream,BDY(t)); |
/* arg1 : prec */ |
Pox_push_cmo(oxarg,&dmy); |
prec = ac == 1 ? 0 : QTOS((Q)ARG1(arg)); |
} |
MKUSINT(ui,prec); |
MKSTR(name,f->name); |
oxarg = mknode(2,ox_pari_stream,ui); |
STOQ(ac,narg); |
Pox_push_cmo(oxarg,&dmy); |
oxarg = mknode(3,ox_pari_stream,name,narg); |
|
Pox_execute_function(oxarg,&dmy); |
/* arg0 : arg */ |
oxarg = mknode(1,ox_pari_stream); |
oxarg = mknode(2,ox_pari_stream,ARG0(arg)); |
Pox_pop_cmo(oxarg,&r); |
Pox_push_cmo(oxarg,&dmy); |
return r; |
|
|
MKSTR(name,f->name); |
|
STOQ(2,narg); |
|
oxarg = mknode(3,ox_pari_stream,name,narg); |
|
Pox_execute_function(oxarg,&dmy); |
|
oxarg = mknode(1,ox_pari_stream); |
|
Pox_pop_cmo(oxarg,&r); |
|
return r; |
|
|
|
case 2: |
|
ac = argc(arg); |
|
if ( !ac || ( ac > 2 ) ) { |
|
fprintf(stderr,"argument mismatch in %s()\n",NAME(f)); |
|
error(""); |
|
/* NOTREACHED */ |
|
return 0; |
|
} |
|
if ( ac == 1 ) |
|
opt = 0; |
|
else |
|
opt = QTOS((Q)ARG1(arg)); |
|
return r; |
|
|
|
default: |
|
error("evalparif : not implemented yet."); |
|
/* NOTREACHED */ |
|
return 0; |
|
} |
|
} |
} |
|
|
struct pariftab { |
struct pariftab { |