diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-06-25 13:00:05 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-06-25 13:00:05 +0000 |
commit | 9c39952768669cae26fed7acd18811fe7aae4d20 (patch) | |
tree | cc6f7e8e0594a0cc1eb890970fcb6b3c70f7e994 /get_str.c | |
parent | b2ad89e8c5e1542e7478d84bd534d626e0034773 (diff) | |
download | mpfr-9c39952768669cae26fed7acd18811fe7aae4d20.tar.gz |
removed DEBUG stuff
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@184 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'get_str.c')
-rw-r--r-- | get_str.c | 45 |
1 files changed, 10 insertions, 35 deletions
@@ -1,10 +1,10 @@ +#include <math.h> #include <stdio.h> #include <stdlib.h> #include "gmp.h" #include "gmp-impl.h" #include "longlong.h" #include "mpfr.h" -#include <math.h> /* Convert op to a string in base 'base' with 'n' digits and writes the @@ -14,8 +14,6 @@ For op = 3.1416 we get str = "31416" and expptr=1. */ -/* #define DEBUG */ - char *mpfr_get_str(char *str, mp_exp_t *expptr, int base, size_t n, mpfr_srcptr op, unsigned char rnd_mode) { @@ -32,10 +30,6 @@ char *mpfr_get_str(char *str, mp_exp_t *expptr, int base, size_t n, if (base != (1<<pow2)) pow2=0; /* if pow2 <> 0, then base = 2^pow2 */ -#ifdef DEBUG - printf("op="); mpfr_print_raw(op); printf(" rnd_mode=%d\n",rnd_mode); - printf(" =%1.20e\n",mpfr_get_d(op)); -#endif /* first determines the exponent */ e = EXP(op); d = fabs(mpfr_get_d2(op, 0)); @@ -44,9 +38,7 @@ char *mpfr_get_str(char *str, mp_exp_t *expptr, int base, size_t n, i.e. f = 1 + floor(log(|op|)/log(base)) = 1 + floor((log(|m|)+e*log(2))/log(base)) */ f = 1 + (int) floor((log(d)+((double)e)*log(2.0))/log((double)base)); -#ifdef DEBUG - printf("exponent = %d\n",f); -#endif + if (n==0) n = (int) ceil((double)PREC(op)*log(2.0)/log((double)base)+ log(4.0*fabs((double)((f==0) ? 1 : f)))/log(2.0)); @@ -59,9 +51,7 @@ char *mpfr_get_str(char *str, mp_exp_t *expptr, int base, size_t n, q = ((q-1)/mp_bits_per_limb)*mp_bits_per_limb; mpfr_init(a); mpfr_init(b); p = n-f; if ((neg=(p<0))) p=-p; -#ifdef DEBUG - printf("n=%d prec=%d p=%d\n",n,prec,p); -#endif + rnd1 = rnd_mode; if (neg) { /* if neg we divide by base^p so we have to invert the rounding mode */ @@ -92,7 +82,7 @@ char *mpfr_get_str(char *str, mp_exp_t *expptr, int base, size_t n, } if (SIGN(op)<0) CHANGE_SIGN(b); if (q>2*prec+mp_bits_per_limb) { - printf("no convergence in mpfr_get_str\n"); exit(1); + fprintf(stderr, "no convergence in mpfr_get_str\n"); exit(1); } } while (pow2==0 && mpfr_can_round(b, q-err, rnd_mode, rnd_mode, prec)==0); if (SIGN(op)<0) @@ -100,41 +90,26 @@ char *mpfr_get_str(char *str, mp_exp_t *expptr, int base, size_t n, case GMP_RNDU: rnd_mode=GMP_RNDZ; break; case GMP_RNDD: rnd_mode=GMP_RNDU; break; } -#ifdef DEBUG -printf("rnd=%d\n",rnd_mode); -printf("b="); mpfr_print_raw(b); putchar('\n'); -printf("=%1.20e\n",mpfr_get_d(b)); -#endif + prec=EXP(b); mpfr_round(b, rnd_mode, prec); - prec=EXP(b); /* may have chnaged due to rounding */ -#ifdef DEBUG -printf("b="); mpfr_print_raw(b); putchar('\n'); -printf("prec=%d q=%d b=",prec,q); mpfr_print_raw(b); putchar('\n'); -printf("=%1.20e\n",mpfr_get_d(b)); -#endif + prec=EXP(b); /* may have changed due to rounding */ + /* now the mantissa is the integer part of b */ - mpz_init(bz); q=1+(prec-1)/mp_bits_per_limb; _mpz_realloc(bz, q); + mpz_init(bz); q=1+(prec-1)/mp_bits_per_limb; + _mpz_realloc(bz, q); sh = prec%mp_bits_per_limb; if (sh) mpn_rshift(PTR(bz), MANT(b), q, mp_bits_per_limb-sh); else MPN_COPY(PTR(bz), MANT(b), q); bz->_mp_size=q; -#ifdef DEBUG -printf("bz="); mpz_out_str(stdout,10,bz); putchar('\n'); -printf("b="); mpfr_print_raw(b); putchar('\n'); -#endif + /* computes the number of characters needed */ q = ((SIGN(op)<0) ? 1 : 0) + n + 1; if (str==NULL) str0=str=malloc(q); if (SIGN(op)<0) *str++='-'; - /* if (n>1) *str++ = '.'; */ mpz_get_str(str, base, bz); /* n digits of mantissa */ if (strlen(str)==n+1) f++; /* possible due to rounding */ - /* str[n++] = 'e'; */ - /* str[n++] = (f>=0) ? '+' : '-'; */ /* is there a rule for f=0 ? */ - /* if (f<10 && f>-10) str[n++]='0'; */ *expptr = f; - /* if (str[-1]=='.') { str[-1]=str[0]; str[0]='.'; } */ mpfr_clear(a); mpfr_clear(b); mpz_clear(bz); return str0; } |