/* mpf_exp.c normalize and use series */ /* e^x = e^j * e^xc integer j, xc = x-j */ /* xc<1/4 series(xc), xc<1/2 series(xc/2)^2, series(xc/4)^4 */ /* 1 + x + x^2/2! + x^3/3! + ... use rfact = 1/factorial */ #include #include #include #include "mpf_exp.h" /* includes gmp and digits*/ static int n = 50; /* need 0.125^n/n! < 10^(-digits) */ static mpf_t zero; static mpf_t one; static mpf_t half; static mpf_t forth; static mpf_t e; static mpf_t temp; static mpf_t sum; static mpf_t prod; static mpf_t xp; static mpf_t rfact[51]; /* reciprocal factorial */ static init = 0; static int debug = 0; #define e1check 2.7182818284590452353602874713526624977572 void series_exp(mpf_t sum, mpf_t xc) /* |xc|<=0.125 */ { int i; mpf_set(xp, xc); mpf_add(sum, one, xc); /* 1 + xc/1! */ for(i=2; i=0) { for(k=0; k