version 1.2, 2015/08/05 01:10:38 |
version 1.4, 2015/08/06 23:41:52 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/builtin/bfaux.c,v 1.1 2015/08/04 06:55:02 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/builtin/bfaux.c,v 1.3 2015/08/05 01:23:02 noro Exp $ */ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
|
|
void Peval(), Psetprec(), Ptodouble(); |
void Peval(), Psetprec(), Psetbprec(), Ptodouble(), Psetround(); |
|
|
struct ftab bf_tab[] = { |
struct ftab bf_tab[] = { |
{"eval",Peval,-2}, |
{"eval",Peval,-2}, |
{"setprec",Psetprec,-1}, |
{"setprec",Psetprec,-1}, |
|
{"setbprec",Psetbprec,-1}, |
|
{"setround",Psetround,-1}, |
{"todouble",Ptodouble,1}, |
{"todouble",Ptodouble,1}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
|
int mpfr_roundmode = MPFR_RNDN; |
|
|
void Ptodouble(NODE arg,Num *rp) |
void Ptodouble(NODE arg,Num *rp) |
{ |
{ |
double r,i; |
double r,i; |
Line 42 void Ptodouble(NODE arg,Num *rp) |
|
Line 46 void Ptodouble(NODE arg,Num *rp) |
|
} |
} |
} |
} |
|
|
void Peval(arg,rp) |
void Peval(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
int prec; |
int prec; |
|
|
asir_assert(ARG0(arg),O_R,"eval"); |
asir_assert(ARG0(arg),O_R,"eval"); |
if ( argc(arg) == 2 ) { |
if ( argc(arg) == 2 ) { |
prec = QTOS((Q)ARG1(arg)); |
prec = QTOS((Q)ARG1(arg))*3.32193; |
if ( prec < MPFR_PREC_MIN ) prec = MPFR_PREC_MIN; |
if ( prec < MPFR_PREC_MIN ) prec = MPFR_PREC_MIN; |
else if ( prec > MPFR_PREC_MAX ) prec = MPFR_PREC_MAX; |
else if ( prec > MPFR_PREC_MAX ) prec = MPFR_PREC_MAX; |
} else |
} else |
|
|
evalr(CO,(Obj)ARG0(arg),prec,rp); |
evalr(CO,(Obj)ARG0(arg),prec,rp); |
} |
} |
|
|
/* bit precision */ |
/* set/get decimal precision */ |
|
|
void Psetprec(NODE arg,Obj *rp) |
void Psetprec(NODE arg,Obj *rp) |
{ |
{ |
int p; |
int p; |
Q q; |
Q q; |
|
int prec,dprec; |
|
|
|
prec = mpfr_get_default_prec(); |
|
/* decimal precision */ |
|
dprec = prec*0.30103; |
|
STOQ(dprec,q); *rp = (Obj)q; |
|
if ( arg ) { |
|
asir_assert(ARG0(arg),O_N,"setprec"); |
|
prec = QTOS((Q)ARG0(arg))*3.32193; |
|
if ( p > 0 ) |
|
prec = p; |
|
} |
|
if ( prec < MPFR_PREC_MIN ) prec = MPFR_PREC_MIN; |
|
else if ( prec > MPFR_PREC_MAX ) prec = MPFR_PREC_MAX; |
|
mpfr_set_default_prec(prec); |
|
} |
|
|
long prec = mpfr_get_default_prec(); |
/* set/get bit precision */ |
|
|
STOQ(prec,q); *rp = (Obj)q; |
void Psetbprec(NODE arg,Obj *rp) |
|
{ |
|
int p; |
|
Q q; |
|
int prec; |
|
|
|
prec = mpfr_get_default_prec(); |
|
STOQ(prec,q); *rp = (Obj)q; |
if ( arg ) { |
if ( arg ) { |
asir_assert(ARG0(arg),O_N,"setprec"); |
asir_assert(ARG0(arg),O_N,"setbprec"); |
p = QTOS((Q)ARG0(arg)); |
prec = QTOS((Q)ARG0(arg)); |
if ( p > 0 ) |
if ( p > 0 ) |
prec = p; |
prec = p; |
} |
} |
Line 79 void Psetprec(NODE arg,Obj *rp) |
|
Line 104 void Psetprec(NODE arg,Obj *rp) |
|
mpfr_set_default_prec(prec); |
mpfr_set_default_prec(prec); |
} |
} |
|
|
|
void Psetround(NODE arg,Q *rp) |
|
{ |
|
int round; |
|
|
|
STOQ(mpfr_roundmode,*rp); |
|
if ( arg ) { |
|
asir_assert(ARG0(arg),O_N,"setround"); |
|
round = QTOS((Q)ARG0(arg)); |
|
switch ( round ) { |
|
case 0: |
|
mpfr_roundmode = MPFR_RNDN; |
|
break; |
|
case 1: |
|
mpfr_roundmode = MPFR_RNDZ; |
|
break; |
|
case 2: |
|
mpfr_roundmode = MPFR_RNDU; |
|
break; |
|
case 3: |
|
mpfr_roundmode = MPFR_RNDD; |
|
break; |
|
case 4: |
|
mpfr_roundmode = MPFR_RNDA; |
|
break; |
|
case 5: |
|
mpfr_roundmode = MPFR_RNDF; |
|
break; |
|
case 6: |
|
mpfr_roundmode = MPFR_RNDNA; |
|
break; |
|
default: |
|
error("setround : invalid rounding mode"); |
|
break; |
|
} |
|
} |
|
} |
|
|
Num tobf(Num a,int prec); |
Num tobf(Num a,int prec); |
|
|
void mp_pi(NODE arg,BF *rp) |
void mp_pi(NODE arg,BF *rp) |
Line 89 void mp_pi(NODE arg,BF *rp) |
|
Line 151 void mp_pi(NODE arg,BF *rp) |
|
prec = arg ? QTOS((Q)ARG0(arg)) : 0; |
prec = arg ? QTOS((Q)ARG0(arg)) : 0; |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_const_pi(r->body,MPFR_RNDN); |
mpfr_const_pi(r->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 103 void mp_e(NODE arg,BF *rp) |
|
Line 165 void mp_e(NODE arg,BF *rp) |
|
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_init(one); |
mpfr_init(one); |
mpfr_set_ui(one,1,MPFR_RNDN); |
mpfr_set_ui(one,1,mpfr_roundmode); |
mpfr_exp(r->body,one,MPFR_RNDN); |
mpfr_exp(r->body,one,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 118 void mp_sin(NODE arg,BF *rp) |
|
Line 180 void mp_sin(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_sin(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_sin(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 132 void mp_cos(NODE arg,BF *rp) |
|
Line 194 void mp_cos(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_cos(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_cos(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 146 void mp_tan(NODE arg,BF *rp) |
|
Line 208 void mp_tan(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_tan(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_tan(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 160 void mp_asin(NODE arg,BF *rp) |
|
Line 222 void mp_asin(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_asin(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_asin(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
void mp_acos(NODE arg,BF *rp) |
void mp_acos(NODE arg,BF *rp) |
Line 173 void mp_acos(NODE arg,BF *rp) |
|
Line 235 void mp_acos(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_acos(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_acos(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
void mp_atan(NODE arg,BF *rp) |
void mp_atan(NODE arg,BF *rp) |
Line 186 void mp_atan(NODE arg,BF *rp) |
|
Line 248 void mp_atan(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_atan(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_atan(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 200 void mp_sinh(NODE arg,BF *rp) |
|
Line 262 void mp_sinh(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_sinh(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_sinh(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 214 void mp_cosh(NODE arg,BF *rp) |
|
Line 276 void mp_cosh(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_cosh(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_cosh(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 228 void mp_tanh(NODE arg,BF *rp) |
|
Line 290 void mp_tanh(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_tanh(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_tanh(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 242 void mp_asinh(NODE arg,BF *rp) |
|
Line 304 void mp_asinh(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_asinh(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_asinh(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
void mp_acosh(NODE arg,BF *rp) |
void mp_acosh(NODE arg,BF *rp) |
Line 255 void mp_acosh(NODE arg,BF *rp) |
|
Line 317 void mp_acosh(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_acosh(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_acosh(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
void mp_atanh(NODE arg,BF *rp) |
void mp_atanh(NODE arg,BF *rp) |
Line 268 void mp_atanh(NODE arg,BF *rp) |
|
Line 330 void mp_atanh(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_atanh(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_atanh(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 282 void mp_exp(NODE arg,BF *rp) |
|
Line 344 void mp_exp(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_exp(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_exp(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 296 void mp_log(NODE arg,BF *rp) |
|
Line 358 void mp_log(NODE arg,BF *rp) |
|
a = tobf(ARG0(arg),prec); |
a = tobf(ARG0(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_log(r->body,((BF)a)->body,MPFR_RNDN); |
mpfr_log(r->body,((BF)a)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |
|
|
Line 311 void mp_pow(NODE arg,BF *rp) |
|
Line 373 void mp_pow(NODE arg,BF *rp) |
|
e = tobf(ARG1(arg),prec); |
e = tobf(ARG1(arg),prec); |
NEWBF(r); |
NEWBF(r); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
mpfr_pow(r->body,((BF)a)->body,((BF)e)->body,MPFR_RNDN); |
mpfr_pow(r->body,((BF)a)->body,((BF)e)->body,mpfr_roundmode); |
*rp = r; |
*rp = r; |
} |
} |