2 documentation bugs (5.0.2)

Tim Van Holder tim.vanholder at anubex.com
Thu Nov 24 16:40:39 CET 2011

First off, a small typo in the "10.1 Formatted Output Strings" topic: "The
precision field has it's usual meaning" - that should be "its", not "it's".

The second doc bug could also be a library bug (depends on whether or not
the behaviour is expected or not).

#include <gmp.h>

#define MPF_BITS 128 /* same with 256 */

main(void) {
  mpf_t f;
  mpf_init2(f, MPF_BITS);
  mpf_set_str(f, "999.9999999", 10);
  gmp_printf("f is either %Ff or %.Ff, depending how you look at it\n", f,
  return 0;

You get as output: "f is either 1000.000000 or 999.9999999, depending how
you look at it" (whereas I had expected the same number to be shown).
The total number of digits seems to be irrelevant (I initially noticed the
problem with 9999999999999999999999.9999999).

Initially seen on a packaged GMP (4.2.3 on SUSE 11.1), and reproduced on a
self-built GMP (5.0.2 from ftp.gmplib.org on that same SUSE system

This "%Ff only prints 6 decimals (with rounding)" behaviour is not
documented (at least not in any obvious location) and led to unpleasant
surprises in our application (1).
Could this restriction be documented? Or, if this is not intended
behaviour, could this be fixed?

(1) COBOL code was being generated using %Ff as format string, and this
resulted in things like a "MOVE 1000.0 TO FIELD", where FIELD only had 3
non-decimal digits (and 7 decimal ones). Due to COBOL assignment rules this
resulted in a value of 0 instead of 999.9999999 - a considerable difference.

More information about the gmp-bugs mailing list