diff options
Diffstat (limited to 'src/number.c')
-rw-r--r-- | src/number.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/number.c b/src/number.c index 5d4cd18..e63427f 100644 --- a/src/number.c +++ b/src/number.c @@ -18,6 +18,10 @@ limitations under the License. #include <stdlib.h> #include <stdio.h> #include <math.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 "definitions.cpp" #include "tools.h" @@ -358,6 +362,30 @@ long double number_double_val(Number x){ } return(ret); } +// approximate numerical expression (as mpfr float) +int number_mpfr_val(mpfr_t out, Number x){ + int i; + // auxiliary variables (do not initialize A) + mpfr_t A,b,c; + mpfr_inits(b,c, (mpfr_ptr)NULL); + + mpfr_init(out); + mpfr_set_zero(out,1); + + for(i=0;i<x.length;i++){ + if(x.scalars[i].numerator!=0){ + mpfr_sqrt_ui(b, x.base[i], MPFR_RNDN); + Q_mpfr_value(A, x.scalars[i]); + mpfr_mul(c, A, b, MPFR_RNDN); + mpfr_add(b, out, c, MPFR_RNDN); + mpfr_set(out, b, MPFR_RNDN); + } + } + + mpfr_clears(A,b,c, (mpfr_ptr)NULL); + + return(0); +} // print to string |