Next: , Up: Extra Number Functions   [Index]


7.1 Extra Rational Number Functions

Macro: MPRIA_MPQ_SET_ZERO (Q)
Macro: MPRIA_MPQ_SET_POS_ONE (Q)
Macro: MPRIA_MPQ_SET_NEG_ONE (Q)
Macro: MPRIA_MPQ_SET_NAN (Q)
Macro: MPRIA_MPQ_SET_POS_INF (Q)
Macro: MPRIA_MPQ_SET_NEG_INF (Q)

Set the value of the rational number Q to 0, +1, -1, 0/0 (NaN), +1/0 (+infinity) and -1/0 (-infinity), respectively. These utility functions are implemented as plain macros (with self-explanatory names).

Macro: MPRIA_MPQ_IS_ZERO (Q)
Macro: MPRIA_MPQ_IS_NONZERO (Q)
Macro: MPRIA_MPQ_IS_POSITIVE (Q)
Macro: MPRIA_MPQ_IS_NEGATIVE (Q)
Macro: MPRIA_MPQ_IS_STRICTLY_POSITIVE (Q)
Macro: MPRIA_MPQ_IS_STRICTLY_NEGATIVE (Q)

Return 1 (read true) if the rational number Q is either zero, nonzero, positive, negative, strictly positive or strictly negative, respectively, 0 (read false) otherwise. These test functions are plain macro functions (with self-explanatory names).

Inline Function: int mpria_mpq_is_nan (const mpq_t op)

Return 1 (read true) if the rational number op is Not-a-Number, 0 (read false) otherwise.

NaN, the acronym for Not-a-Number, has the representation 0/0.4

Inline Function: int mpria_mpq_is_infinite (const mpq_t op)

Return +1 if the rational number op is positive infinity, -1 if it is negative infinity, 0 otherwise.

Positive and negative infinities have the representation +1/0 and -1/0, respectively;5 they are commonly written +infinity and -infinity, respectively.

Inline Function: int mpria_mpq_is_finite (const mpq_t op)

Return 1 (read true) if the rational number op is finite, 0 (read false) if it is either infinite or Not-a-Number.

Inline Function: int mpria_mpq_sgn (const mpq_t op)

Return +1 if the rational op is strictly positive, 0 if it is zero, or -1 if it is strictly negative. Its behaviour stays undefined if its argument is NaN (0/0).
While its counterpart mpq_sgn is implemented as a macro, this function is implemented as an inline function: it evaluates its argument only once.

Function: int mpria_mpq_cmpabs (const mpq_t op1, const mpq_t op2)

Compare the absolute values of the rational numbers op1 and op2. Return either a positive value if abs(op1) is strictly greater than abs(op2), zero if abs(op1) is equal to abs(op2), or a negative value if abs(op1) is strictly smaller than abs(op2). Its behaviour remains undefined if at least one of its arguments is either -infinity (-1/0), +infinity (+1/0), or NaN (0/0).

Inline Function: void mpria_mpq_min3 (mpq_t rop, const mpq_t op1, const mpq_t op2, const mpq_t op3)

Set the value of rop to the minimum of the triplet {op1,op2,op3}. Its behaviour is undefined if the triplet contains -infinity (-1/0), +infinity (+1/0), or NaN (0/0).


Footnotes

(4)

At the time of writing, GMP does not support NaN for mpq_t numbers.

(5)

At the time of writing, GMP does not support infinities for mpq_t numbers.


Next: , Up: Extra Number Functions   [Index]