GNU MPFR 3.1.4: Compatibility with MPF
Description: How to install and use GNU MPFR, a library for reliable multiple precision floating-point arithmetic, version 3.1.4.

Next: Custom Interface, Previous: Exception Related Functions, Up: MPFR Interface [Index]

### 5.14 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>

any program written for MPF can be compiled directly with MPFR without any changes (except the `gmp_printf` functions will not work for arguments of type `mpfr_t`). All operations are then performed with the default MPFR rounding mode, which can be reset with `mpfr_set_default_rounding_mode`.

Warning: the `mpf_init` and `mpf_init2` functions initialize to zero, whereas the corresponding MPFR functions initialize to NaN: this is useful to detect uninitialized values, but is slightly incompatible with MPF.

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: Exception Related Functions, Up: MPFR Interface [Index]