diff options
author | Ian Jauslin <ian.jauslin@roma1.infn.it> | 2015-10-07 12:51:41 +0000 |
---|---|---|
committer | Ian Jauslin <ian.jauslin@roma1.infn.it> | 2015-10-07 13:00:23 +0000 |
commit | 469bdc80712dbf9c12562059dc4594620b59a076 (patch) | |
tree | c6da40a884899110d102d82a7a778f2b3afae702 /src/rational_float.c | |
parent | e7aa6859f08565d58684fa4b9c40fed716f0ba17 (diff) |
Support MPFR floats in numkondov1.4
Remove '-D' option (error tolerance) in numkondo
Diffstat (limited to 'src/rational_float.c')
-rw-r--r-- | src/rational_float.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/rational_float.c b/src/rational_float.c index eebc4f4..d6a6a4c 100644 --- a/src/rational_float.c +++ b/src/rational_float.c @@ -19,21 +19,14 @@ limitations under the License. #include "rational_float.h" #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> +// define MPFR_USE_VA_LIST to enable the use of mpfr_inits and mpfr_clears +#define MPFR_USE_VA_LIST +#include <mpfr.h> #include "istring.h" #include "array.h" #include "math.h" -Q quot(long double p, long double q){ - Q ret; - if(q==0){ - fprintf(stderr,"error: %Lf/%Lf is ill defined\n",p,q); - exit(-1); - } - ret.numerator=p; - ret.denominator=q; - return(ret); -} - // add Q Q_add(Q x1,Q x2){ Q ret; @@ -141,6 +134,16 @@ long double lcm(long double x,long double y){ double Q_double_value(Q q){ return(1.0*q.numerator/q.denominator); } +// approximate value as mpfr float +int Q_mpfr_value(mpfr_t out, Q q){ + mpfr_t x; + mpfr_init(out); + mpfr_init(x); + mpfr_set_ld(x, q.denominator, MPFR_RNDN); + mpfr_ld_div(out, q.numerator, x, MPFR_RNDN); + mpfr_clear(x); + return(0); +} // print to string |