Next: , Previous: Integer Related Functions, Up: MPFR Interface


5.10 Miscellaneous Functions

— Function: void mpfr_nexttoward (mpfr_t x, mpfr_t y)

If x or y is NaN, set x to NaN. Otherwise, if x is different from y, replace x by the next floating-point number (with the precision of x and the current exponent range) in the direction of y, if there is one (the infinite values are seen as the smallest and largest floating-point numbers). If the result is zero, it keeps the same sign. No underflow or overflow is generated.

— Function: void mpfr_nextabove (mpfr_t x)

Equivalent to mpfr_nexttoward where y is plus infinity.

— Function: void mpfr_nextbelow (mpfr_t x)

Equivalent to mpfr_nexttoward where y is minus infinity.

— Function: int mpfr_min (mpfr_t rop, mpfr_t op1, mpfr_t op2, mp_rnd_t rnd)

Set rop to the minimum of op1 and op2. If op1 and op2 are both NaN, then rop is set to NaN. If op1 or op2 is NaN, then rop is set to the numeric value. If op1 and op2 are zeros of different signs, then rop is set to −0.

— Function: int mpfr_max (mpfr_t rop, mpfr_t op1, mpfr_t op2, mp_rnd_t rnd)

Set rop to the maximum of op1 and op2. If op1 and op2 are both NaN, then rop is set to NaN. If op1 or op2 is NaN, then rop is set to the numeric value. If op1 and op2 are zeros of different signs, then rop is set to +0.

— Function: int mpfr_urandomb (mpfr_t rop, gmp_randstate_t state)

Generate a uniformly distributed random float in the interval 0 <= rop < 1. Return 0, unless the exponent is not in the current exponent range, in which case rop is set to NaN and a non-zero value is returned. The second argument is a gmp_randstate_t structure which should be created using the GMP gmp_randinit function, see the GMP manual.

— Function: void mpfr_random (mpfr_t rop)

Generate a uniformly distributed random float in the interval 0 <= rop < 1. This function is deprecated; mpfr_urandomb should be used instead.

— Function: void mpfr_random2 (mpfr_t rop, mp_size_t size, mp_exp_t exp)

Generate a random float of at most size limbs, with long strings of zeros and ones in the binary representation. The exponent of the number is in the interval −exp to exp. This function is useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. Negative random numbers are generated when size is negative. Put +0 in rop when size if zero.

— Function: mp_exp_t mpfr_get_exp (mpfr_t x)

Get the exponent of x, assuming that x is a non-zero ordinary number. The behavior for NaN, Infinity or Zero is undefined.

— Function: int mpfr_set_exp (mpfr_t x, mp_exp_t e)

Set the exponent of x if e is in the current exponent range, and return 0 (even if x is not a non-zero ordinary number); otherwise, return a non-zero value.

— Function: const char * mpfr_get_version (void)

Return the MPFR version, as a null-terminated string.

— Macro: MPFR_VERSION
— Macro: MPFR_VERSION_MAJOR
— Macro: MPFR_VERSION_MINOR
— Macro: MPFR_VERSION_PATCHLEVEL
— Macro: MPFR_VERSION_STRING

MPFR_VERSION is the version of MPFR as a preprocessing constant. MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR and MPFR_VERSION_PATCHLEVEL are respectively the major, minor and patch level of MPFR version, as preprocessing constants. MPFR_VERSION_STRING is the version as a string constant, which can be compared to the result of mpfr_get_version to check at run time the header file and library used match:

          if (strcmp (mpfr_get_version (), MPFR_VERSION_STRING))
             fprintf (stderr, "Error, header and library files do not match\n");
     
— Macro: long MPFR_VERSION_NUM (major, minor, patchlevel)

Create an integer in the same format as used by MPFR_VERSION from the given major, minor and patchlevel. Here is an example of how to check the MPFR version at compile time:

          #if (!defined(MPFR_VERSION) || (MPFR_VERSION<MPFR_VERSION_NUM(2,1,0)))
          # error "Wrong MPFR version."
          #endif