Frequently Asked Questions about MPFR

Important notice: Problems with a particular version of MPFR are discussed in the corresponding bugs page.

The latest version of this FAQ is available at http://www.mpfr.org/faq.html.

What are the differences between MPF from GMP and MPFR?
Unlike MPF, the precision of a MPFR variable is the exact number of bits used for its mantissa. This implies that MPFR results do not depend on the number of bits (16, 32, 64 or more) of the underlying architecture. Also, MPFR provides an additional rounding mode argument to its functions; furthermore, it is guaranteed that the result of any operation is the nearest possible floating-point value from the exact result (considering the input variables as exact values), taking into account the precision of the destination variable and the rounding mode.
How to convert my program written using MPF to MPFR?
You need to add r to the function names, and to specify the rounding mode (GMP_RNDN for rounding to nearest, GMP_RNDZ for rounding towards zero, GMP_RNDU for rounding towards plus infinity, GMP_RNDD for rounding towards minus infinity). You can also define macros as follows:
#define mpf_add(a, b, c) mpfr_add(a, b, c, GMP_RNDN)
The header file mpf2mpfr.h from the MPFR distribution automatically redefines all MPF functions in this way, using the default MPFR rounding mode. Thus you simply need to add the following line in all your files using MPF functions:
#include <mpf2mpfr.h>
just after the gmp.h and mpfr.h header files.
When I link my program with MPFR, I get undefined reference to __gmpz_XXXX, __gmpn_XXXX.
Link your program with GMP. Assuming that your program is foo.c, you should link it using:
    cc link.c -lmpfr -lgmp
MPFR library reference (-lmpfr) should be before GMP's one (-lgmp). Another solution is, with GNU ld, to give all the libraries inside a group:
    gcc link.c -Wl,--start-group libgmp.a libmpfr.a -Wl,--end-group
See ld manual for more details.
My program crashes with high precisions.
Your stack size limit may be too small. You can increase it with the limit, unlimit or ulimit command, depending on your shell.