Bug Report GMP-5.1.1 Mini-gmp t-double.c

Michael Tate michael.tate at wanadoo.fr
Mon Feb 25 12:58:36 CET 2013

Hello, I have come across a possible failure in the mini-gmp test suite and
have decided to submit a report.

1) Gmp version:5.1.1
2) Built from tarball using standard options
3) Using  gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8

Requested Outputs:
uname -a:
Linux n110-fc18-ssd 3.7.8-202.fc18.i686.PAE #1 SMP Fri Feb 15 17:47:05 
UTC 2013 i686 i686 i386 GNU/Linux


Running 'make check' in mini-gmp/tests produces an error in t-double.c
Partial output follows:
PASS: t-add
PASS: t-sub
PASS: t-mul
PASS: t-invert
PASS: t-div
PASS: t-div_2exp
mpz_cmp_d (x, f) failed:
x: 87f41fe00000000
memory clobbered before allocated block
./run-tests: line 57:  4383 Aborted                 (core dumped) "$1" 
FAIL: t-double
PASS: t-cmp_d
PASS: t-gcd
PASS: t-lcm
PASS: t-import
PASS: t-comb
PASS: t-signed
PASS: t-sqrt
PASS: t-root
PASS: t-powm
PASS: t-logops
PASS: t-bitops
PASS: t-scan
PASS: t-str
PASS: t-reuse
1 of 21 tests failed

I believe I have found the cause of this problem. The test program
increments/decrements a double by 1.0 during the course of testing. If
the double has more than 16 digits of precision, then the inc/dec fails
to take effect and the succeeding test fails.

Code Block:
       if ((f == d) ? (mpz_cmp_d (x, d) != 0) : (mpz_cmp_d (x, d) >= 0))
       fprintf (stderr, "mpz_cmp_d (x, d) failed:\n");
       goto dumperror;

       // This increment fails if double has more than 16 digits of 
       // Sample values: x=612280633523175424 
f=612280633523175424.000000  d=612280633523175424.000000

       f = d + 1.0;

       if (f > d && ! (mpz_cmp_d (x, f) < 0))
       fprintf (stderr, "mpz_cmp_d (x, f) failed:\n");
       goto dumperror;

Possible solution:
I have rewritten the t-double.c routine using a much more conservative
random double generator, using about 15 digits of precision, and this
seems to work correctly.

Thank you for all your work on the library. I hope the
report may be of some help.

Best wishes

More information about the gmp-bugs mailing list