Next: Special Functions, Previous: Basic Arithmetic Functions, Up: MPFR Interface [Index]

### 5.6 Comparison Functions

Function: int mpfr_cmp (mpfr_t op1, mpfr_t op2)
Function: int mpfr_cmp_ui (mpfr_t op1, unsigned long int op2)
Function: int mpfr_cmp_si (mpfr_t op1, long int op2)
Function: int mpfr_cmp_d (mpfr_t op1, double op2)
Function: int mpfr_cmp_ld (mpfr_t op1, long double op2)
Function: int mpfr_cmp_z (mpfr_t op1, mpz_t op2)
Function: int mpfr_cmp_q (mpfr_t op1, mpq_t op2)
Function: int mpfr_cmp_f (mpfr_t op1, mpf_t op2)

  Compare op1 and op2. Return a positive value if op1 > op2, zero if op1 = op2, and a negative value if op1 < op2. Both op1 and op2 are considered to their full own precision, which may differ. If one of the operands is NaN, set the erange flag and return zero.

  Note: These functions may be useful to distinguish the three possible cases. If you need to distinguish two cases only, it is recommended to use the predicate functions (e.g., `mpfr_equal_p` for the equality) described below; they behave like the IEEE 754 comparisons, in particular when one or both arguments are NaN. But only floating-point numbers can be compared (you may need to do a conversion first).

Function: int mpfr_cmp_ui_2exp (mpfr_t op1, unsigned long int op2, mpfr_exp_t e)
Function: int mpfr_cmp_si_2exp (mpfr_t op1, long int op2, mpfr_exp_t e)

  Compare op1 and op2 multiplied by two to the power e. Similar as above.

Function: int mpfr_cmpabs (mpfr_t op1, mpfr_t op2)

  Compare |op1| and |op2|. Return a positive value if |op1| > |op2|, zero if |op1| = |op2|, and a negative value if |op1| < |op2|. If one of the operands is NaN, set the erange flag and return zero.

Function: int mpfr_nan_p (mpfr_t op)
Function: int mpfr_inf_p (mpfr_t op)
Function: int mpfr_number_p (mpfr_t op)
Function: int mpfr_zero_p (mpfr_t op)
Function: int mpfr_regular_p (mpfr_t op)

  Return non-zero if op is respectively NaN, an infinity, an ordinary number (i.e., neither NaN nor an infinity), zero, or a regular number (i.e., neither NaN, nor an infinity nor zero). Return zero otherwise.

Macro: int mpfr_sgn (mpfr_t op)

  Return a positive value if op > 0, zero if op = 0, and a negative value if op < 0. If the operand is NaN, set the erange flag and return zero. This is equivalent to `mpfr_cmp_ui (op, 0)`, but more efficient.

Function: int mpfr_greater_p (mpfr_t op1, mpfr_t op2)
Function: int mpfr_greaterequal_p (mpfr_t op1, mpfr_t op2)
Function: int mpfr_less_p (mpfr_t op1, mpfr_t op2)
Function: int mpfr_lessequal_p (mpfr_t op1, mpfr_t op2)
Function: int mpfr_equal_p (mpfr_t op1, mpfr_t op2)

  Return non-zero if op1 > op2, op1 >= op2, op1 < op2, op1 <= op2, op1 = op2 respectively, and zero otherwise. Those functions return zero whenever op1 and/or op2 is NaN.

Function: int mpfr_lessgreater_p (mpfr_t op1, mpfr_t op2)

  Return non-zero if op1 < op2 or op1 > op2 (i.e., neither op1, nor op2 is NaN, and op1 <> op2), zero otherwise (i.e., op1 and/or op2 is NaN, or op1 = op2).

Function: int mpfr_unordered_p (mpfr_t op1, mpfr_t op2)

  Return non-zero if op1 or op2 is a NaN (i.e., they cannot be compared), zero otherwise.

Next: Special Functions, Previous: Basic Arithmetic Functions, Up: MPFR Interface [Index]