Confusion with gmp_printf

Torbjorn Granlund tg at
Sun Jan 25 16:32:32 CET 2009

"Bruce M. Axtens" <bruce.axtens at> writes:

      mpf_t f;
      int n;
      gmp_printf ("fixed point mpf %.*Ff with %d digits\n", n, f, n);
  In section 10.1 of the 4.2.4 manual, the above is given as an example of 
  how to print an mpf number. What I don't understand is how that works 
  given that 'n' is either zero or undefined (depending on C or compiler).
It is assumed that both f and n is set to something useful.

  How do I get gmp_printf (or, in my case, gmp_sprintf) to output 
  everything that's in an mpf_t without rounding.
As far as I know, gmp_*printf does not provide any such feature, but I
am too lazy to check the manual right now.

If I am right, you need to do the logarithm fraction, and compute the
value of n from the number of bits you asked for when initializing f.

log(2)/log(10) = 0.3010299957...


More information about the gmp-discuss mailing list