bug in gmp_printf (?)
Paul.Zimmermann at loria.fr
Thu Aug 18 00:10:17 CEST 2011
> test=doprntf.c:128 GNU MP assertion failed: (p-)conv == 1 && p->prec ...
> I would be grateful if some other GMP developer could help with this.
> The bug is for real, to reproduce configure with --enable-assert. I
> haven't analysed if the ASSERT is wrong, or if it is a more serious
> All relevant code is a few lines in printf/doprntf.c.
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.
PS: apparently "make check" exercises no case with EXP(f)=0 and exp=1.
More information about the gmp-bugs