1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include <mpfi.h>
#include <mpfr.h>
#include <time.h>
#include <sollya.h>
int myownlog(mpfi_t result, mpfi_t x, int n) {
if(n==0) {
/* Implementation of the neperian logarithm */
if(mpfi_nan_p(x)) {
mpfr_t a;
mpfr_init2(a,mpfi_get_prec(result));
mpfi_interv_fr(result,a,a);
mpfr_clear(a);
return 0;
}
if(mpfi_has_zero(x)) {
mpfr_t a,b;
mpfr_init2(a,mpfi_get_prec(result));
mpfr_init2(b,mpfi_get_prec(result));
mpfr_set_inf(a,-1);
mpfi_get_right(b,x);
mpfr_log(b,b,GMP_RNDU);
mpfi_interv_fr(result, a, b);
mpfr_clear(a);
mpfr_clear(b);
return 0;
}
else {
mpfr_t a,b;
mpfr_init2(a,mpfi_get_prec(result));
mpfr_init2(b,mpfi_get_prec(result));
mpfi_get_left(a,x);
mpfr_log(a,a, GMP_RNDD);
mpfi_get_right(b,x);
mpfr_log(b,b,GMP_RNDU);
mpfi_interv_fr(result, a, b);
mpfr_clear(a);
mpfr_clear(b);
return 0;
}
}
if(n==1) {
/* Implementation of 1/x */
mpfi_inv(result,x);
return 0;
}
if(n==2) {
/* Implementation of -1/x^2 */
mpfi_t temp;
mpfi_init2(temp, mpfi_get_prec(result));
mpfi_sqr(temp, x);
mpfi_inv(temp, temp);
mpfi_neg(result, temp);
mpfi_clear(temp);
return 0;
}
/* else */
mpfr_t a,b;
mpfr_init2(a, mpfi_get_prec(result));
mpfr_init2(b, mpfi_get_prec(result));
mpfr_set_inf(a,-1);
mpfr_set_inf(b, 1);
mpfi_interv_fr(result,a,b);
mpfr_clear(a);
mpfr_clear(b);
return 0;
}
void euler_gamma(mpfr_t res, mp_prec_t prec) {
mpfr_set_prec(res, prec);
mpfr_const_euler(res, GMP_RNDN);
return;
}
int funny_impl(char *str, int i, mpfr_t v) {
printf(">>>%s<<<>>>%d<<<>>>%ld<<<\n", str, i, (long int) mpfr_get_si(v,GMP_RNDN));
return (i == 17);
}
int funny(int *res, void **args) {
*res = funny_impl(((char *) (args[0])), *((int *) (args[1])), *((mpfr_t *) (args[2])));
return 1;
}
int zeit_impl() {
return (int) time(NULL);
}
int zeit(int *res) {
*res = zeit_impl();
return 1;
}
|