*(gmp.info.gz)* Initializing Rationals

Info Catalog
*(gmp.info.gz)* **Rational Number Functions**
*(gmp.info.gz)* **Rational Number Functions**
*(gmp.info.gz)* **Rational Conversions**
Initialization and Assignment Functions
=======================================
*- Function: void mpq_init (mpq_t DEST_RATIONAL)*
Initialize DEST_RATIONAL and set it to 0/1. Each variable should
normally only be initialized once, or at least cleared out (using
the function `mpq_clear') between each initialization.
*- Function: void mpq_clear (mpq_t RATIONAL_NUMBER)*
Free the space occupied by RATIONAL_NUMBER. Make sure to call this
function for all `mpq_t' variables when you are done with them.
*- Function: void mpq_set (mpq_t ROP, mpq_t OP)*
*- Function: void mpq_set_z (mpq_t ROP, mpz_t OP)*
Assign ROP from OP.
*- Function: void mpq_set_ui (mpq_t ROP, unsigned long int OP1,*
unsigned long int OP2)
*- Function: void mpq_set_si (mpq_t ROP, signed long int OP1, unsigned*
long int OP2)
Set the value of ROP to OP1/OP2. Note that if OP1 and OP2 have
common factors, ROP has to be passed to `mpq_canonicalize' before
any operations are performed on ROP.
*- Function: int mpq_set_str (mpq_t ROP, char *STR, int BASE)*
Set ROP from a null-terminated string STR in the given BASE.
The string can be an integer like "41" or a fraction like
"41/152". The fraction must be in canonical form ( Rational
Number Functions), or if not then `mpq_canonicalize' must be
called.
The numerator and optional denominator are parsed the same as in
`mpz_set_str' ( Assigning Integers). White space is
allowed in the string, and is simply ignored. The BASE can vary
from 2 to 62, or if BASE is 0 then the leading characters are
used: `0x' or `0X' for hex, `0b' or `0B' for binary, `0' for
octal, or decimal otherwise. Note that this is done separately
for the numerator and denominator, so for instance `0xEF/100' is
239/100, whereas `0xEF/0x100' is 239/256.
The return value is 0 if the entire string is a valid number, or
-1 if not.
*- Function: void mpq_swap (mpq_t ROP1, mpq_t ROP2)*
Swap the values ROP1 and ROP2 efficiently.

Info Catalog
*(gmp.info.gz)* **Rational Number Functions**
*(gmp.info.gz)* **Rational Number Functions**
*(gmp.info.gz)* **Rational Conversions**

*automatically generated by***info2html**