bug in gmp_printf (?)

Marc Glisse marc.glisse at inria.fr
Thu Aug 18 13:50:25 CEST 2011


On Thu, 18 Aug 2011, Zimmermann Paul wrote:

> the problem is that when ndigits is first calculated:
>
>        ndigits = prec + 2
>          + EXP(f) * (mp_bases[ABS(p->base)].chars_per_limb + (EXP(f)>=0));
>
> EXP(f) is 0, since the number is just below 1. But in the mpf_get_str call,
> we get exp=1, thus the number is rounded up to 1 (we get s=1 as significand).
> Thus the assumption ndigits >= MAX (1, exp + p->prec + 2) is false.
>
> When EXP(f)<>0, I guess the problem cannot occur, since as the comment
> explains it, the number of extra zeros is either over- or under-estimated,
> thus the assertion holds (it would be good if someone could double check).
>
> The only problem can happen when EXP(f)=0. I suggest replacing prec + 2
> by prec + 2 + (EXP(f) == 0) above, or by prec + 3 to be sure.
>
> Paul
>
> PS: apparently "make check" exercises no case with EXP(f)=0 and exp=1.

Hello,

so you think the issue is wider than just <1 rounded to exactly 1, and 
that it can indeed cause real trouble?

-- 
Marc Glisse


More information about the gmp-bugs mailing list