gmp_printf bug?

Torbjorn Granlund tg at gmplib.org
Wed Jul 20 10:01:35 CEST 2011


Zimmermann Paul <Paul.Zimmermann at loria.fr> writes:

  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
  0.111349511949672485115e405025890106316193
  *** glibc detected *** ./a.out: realloc(): invalid pointer: 0x00000000018c1008 ***

I am unable to reproduce this problem.

I attempted to reproduce it on both the main GMP development machine
(athlon64-pc-freebsd8.1) and on a GNU/Linux machine (x86_64-linux-gnu).

There is surely a bug somewhere, in GMP or in the environment you're
using (e.g., glibc).  It would be good if someone could isolate the
problem.

-- 
Torbjörn


More information about the gmp-bugs mailing list