diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-01-15 14:43:17 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-01-15 14:43:17 +0000 |
commit | da0568f9f7d0dc903649e31a3a93a48e7f12cee4 (patch) | |
tree | 47c2164284c8599239ffc7f1097cd5e881378a86 /get_str.c | |
parent | c276f575ff672940ef47253dea49f6641890ec45 (diff) | |
download | mpfr-da0568f9f7d0dc903649e31a3a93a48e7f12cee4.tar.gz |
fixed problem in case m=0 and b=2^k (lost bits from 1st digit were not taken
into account)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2625 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'get_str.c')
-rw-r--r-- | get_str.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -547,8 +547,25 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd if (m == 0) { - m = (size_t) _mpfr_ceil (__mp_bases[b].chars_per_bit_exactly - * (double) MPFR_PREC(x)); + + m = MPFR_PREC(x); + if (IS_POW2(b) && b >= 4) + /* when the base is a power of two, we can compute exactly the number + of digits sufficient to print the number exactly. + Warning: we may loose some bits in the first digit. + If EXP(x)=0, no bit is lost. + If EXP(x)=-1, one bit is lost... */ + { + int k, lost; + + count_leading_zeros (k, (mp_limb_t) b); + k = BITS_PER_MP_LIMB - k - 1; /* b = 2^k */ + lost = (-MPFR_EXP(x)) % k; + if (lost < 0) + lost += k; + m += lost; + } + m = (size_t) _mpfr_ceil (__mp_bases[b].chars_per_bit_exactly * (double) m); if (m < 2) m = 2; } |