version 1.3, 2015/08/05 01:23:02 |
version 1.7, 2015/08/07 08:00:30 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/builtin/bfaux.c,v 1.2 2015/08/05 01:10:38 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/builtin/bfaux.c,v 1.6 2015/08/07 06:15:00 takayama Exp $ */ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
|
|
void Peval(), Psetprec(), Psetbprec(), Ptodouble(); |
void Peval(), Psetprec(), Psetbprec(), Ptodouble(), Psetround(); |
|
void Pmpfr_gamma(), Pmpfr_floor(), Pmpfr_round(); |
|
|
struct ftab bf_tab[] = { |
struct ftab bf_tab[] = { |
{"eval",Peval,-2}, |
{"eval",Peval,-2}, |
{"setprec",Psetprec,-1}, |
{"setprec",Psetprec,-1}, |
{"setbprec",Psetbprec,-1}, |
{"setbprec",Psetbprec,-1}, |
|
{"setround",Psetround,-1}, |
{"todouble",Ptodouble,1}, |
{"todouble",Ptodouble,1}, |
|
{"mpfr_gamma",Pmpfr_gamma,-2}, |
|
{"mpfr_floor",Pmpfr_floor,-1}, |
|
{"mpfr_round",Pmpfr_round,-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 43 void Ptodouble(NODE arg,Num *rp) |
|
Line 50 void Ptodouble(NODE arg,Num *rp) |
|
} |
} |
} |
} |
|
|
void Peval(arg,rp) |
void Peval(NODE arg,Obj *rp) |
NODE arg; |
|
Obj *rp; |
|
{ |
{ |
int prec; |
int prec; |
|
|
Line 103 void Psetbprec(NODE arg,Obj *rp) |
|
Line 108 void Psetbprec(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 113 void mp_pi(NODE arg,BF *rp) |
|
Line 155 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 127 void mp_e(NODE arg,BF *rp) |
|
Line 169 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 142 void mp_sin(NODE arg,BF *rp) |
|
Line 184 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 156 void mp_cos(NODE arg,BF *rp) |
|
Line 198 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 170 void mp_tan(NODE arg,BF *rp) |
|
Line 212 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 184 void mp_asin(NODE arg,BF *rp) |
|
Line 226 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 197 void mp_acos(NODE arg,BF *rp) |
|
Line 239 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 210 void mp_atan(NODE arg,BF *rp) |
|
Line 252 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 224 void mp_sinh(NODE arg,BF *rp) |
|
Line 266 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 238 void mp_cosh(NODE arg,BF *rp) |
|
Line 280 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 252 void mp_tanh(NODE arg,BF *rp) |
|
Line 294 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 266 void mp_asinh(NODE arg,BF *rp) |
|
Line 308 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 279 void mp_acosh(NODE arg,BF *rp) |
|
Line 321 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 292 void mp_atanh(NODE arg,BF *rp) |
|
Line 334 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 306 void mp_exp(NODE arg,BF *rp) |
|
Line 348 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 320 void mp_log(NODE arg,BF *rp) |
|
Line 362 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 335 void mp_pow(NODE arg,BF *rp) |
|
Line 377 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; |
|
} |
|
|
|
void Pmpfr_gamma(NODE arg,BF *rp) |
|
{ |
|
Num a; |
|
int prec; |
|
BF r; |
|
|
|
prec = NEXT(arg) ? QTOS((Q)ARG1(arg)) : 0; |
|
prec *= 3.32193; |
|
a = tobf(ARG0(arg),prec); |
|
NEWBF(r); |
|
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
|
mpfr_gamma(r->body,((BF)a)->body,mpfr_roundmode); |
|
*rp = r; |
|
} |
|
|
|
void Pmpfr_floor(NODE arg,Q *rp) |
|
{ |
|
Num a; |
|
int prec; |
|
BF r; |
|
mpz_t t; |
|
GZ rz; |
|
|
|
prec = NEXT(arg) ? QTOS((Q)ARG1(arg)) : 0; |
|
prec *= 3.32193; |
|
a = tobf(ARG0(arg),prec); |
|
NEWBF(r); |
|
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
|
mpfr_floor(r->body,((BF)a)->body); |
|
mpz_init(t); |
|
mpfr_get_z(t,r->body,mpfr_roundmode); |
|
MPZTOGZ(t,rz); |
|
*rp = gztoz(rz); |
|
} |
|
|
|
void Pmpfr_round(NODE arg,Q *rp) |
|
{ |
|
Num a; |
|
int prec; |
|
BF r; |
|
mpz_t t; |
|
GZ rz; |
|
|
|
prec = NEXT(arg) ? QTOS((Q)ARG1(arg)) : 0; |
|
prec *= 3.32193; |
|
a = tobf(ARG0(arg),prec); |
|
NEWBF(r); |
|
prec ? mpfr_init2(r->body,prec) : mpfr_init(r->body); |
|
mpfr_round(r->body,((BF)a)->body); |
|
mpz_init(t); |
|
mpfr_get_z(t,r->body,mpfr_roundmode); |
|
MPZTOGZ(t,rz); |
|
*rp = gztoz(rz); |
} |
} |