Next: Custom Interface, Previous: Memory Handling Functions, Up: MPFR Interface [Index]

### 5.15 Compatibility With MPF

A header file `mpf2mpfr.h` is included in the distribution of MPFR for compatibility with the GNU MP class MPF. By inserting the following two lines after the `#include <gmp.h>` line,

    #include <mpfr.h>
    #include <mpf2mpfr.h>

many programs written for MPF can be compiled directly against MPFR without any changes. All operations are then performed with the default MPFR rounding mode, which can be reset with `mpfr_set_default_rounding_mode`.

Warning! There are some differences. In particular:

- The precision is different: MPFR rounds to the exact number of bits (zeroing trailing bits in the internal representation). Users may need to increase the precision of their variables.
- The exponent range is also different.
- The formatted output functions (`gmp_printf`, etc.) will not work for arguments of arbitrary-precision floating-point type (`mpf_t`, which `mpf2mpfr.h` redefines as `mpfr_t`).
- The output of `mpf_out_str` has a format slightly different from the one of `mpfr_out_str` (concerning the position of the decimal-point character, trailing zeros and the output of the value 0).

Function: void mpfr_set_prec_raw (mpfr_t x, mpfr_prec_t prec)

  Reset the precision of x to be exactly prec bits. The only difference with `mpfr_set_prec` is that prec is assumed to be small enough so that the significand fits into the current allocated memory space for x. Otherwise the behavior is undefined.

Function: int mpfr_eq (mpfr_t op1, mpfr_t op2, unsigned long int op3)

  Return non-zero if op1 and op2 are both non-zero ordinary numbers with the same exponent and the same first op3 bits, both zero, or both infinities of the same sign. Return zero otherwise. This function is defined for compatibility with MPF, we do not recommend to use it otherwise. Do not use it either if you want to know whether two numbers are close to each other; for instance, 1.011111 and 1.100000 are regarded as different for any value of op3 larger than 1.

Function: void mpfr_reldiff (mpfr_t rop, mpfr_t op1, mpfr_t op2, mpfr_rnd_t rnd)

  Compute the relative difference between op1 and op2 and store the result in rop. This function does not guarantee the correct rounding on the relative difference; it just computes |op1-op2|/op1, using the precision of rop and the rounding mode rnd for all operations.

Function: int mpfr_mul_2exp (mpfr_t rop, mpfr_t op1, unsigned long int op2, mpfr_rnd_t rnd)
Function: int mpfr_div_2exp (mpfr_t rop, mpfr_t op1, unsigned long int op2, mpfr_rnd_t rnd)

  These functions are identical to `mpfr_mul_2ui` and `mpfr_div_2ui` respectively. These functions are only kept for compatibility with MPF, one should prefer `mpfr_mul_2ui` and `mpfr_div_2ui` otherwise.

Next: Custom Interface, Previous: Memory Handling Functions, Up: MPFR Interface [Index]