gmp_printf bug?

Zimmermann Paul Paul.Zimmermann at
Tue Jul 19 09:03:39 CEST 2011


following a problem reported on the MPFR list, it seems gmp_printf has strange
limitations for large floating-point values. Consider the following code:

#include <stdio.h>
#include <stdlib.h>
#include "gmp.h"

main(int argc, char *argv[])
  mpf_t f;

  mpf_init2 (f, 2);
  mpf_set_ui (f, 1);
  mpf_mul_2exp (f, f, 1345466883500933130);
  mpf_dump (f);
  gmp_printf("%Fe\n", f);
  mpf_clear (f);

It yields on a 64-bit computer:

tarte% ./a.out
*** glibc detected *** ./a.out: realloc(): invalid pointer: 0x00000000018c1008 ***
======= Backtrace: =========

Note that the mpf_dump call succeeds, but gmp_printf fails.

With mpf_mul_2exp (f, f, 1345466883500933129) both functions succeed.

I have no idea why this limit of 1345466883500933130 which is not near a power
of two (it is about 2^60.22).

Paul Zimmermann

More information about the gmp-bugs mailing list