gmp_libmpq_get_num Method |
Namespace: Math.Gmp.Native
The function is equivalent to calling mpz_set with mpq_numref. Direct use of mpq_numref is recommended instead of this functions.
// Create, initialize, and set the value of op to -1 / 3. mpq_t op = new mpq_t(); gmp_lib.mpq_init(op); gmp_lib.mpq_set_si(op, -1, 3U); // Create and initialize a new integer. mpz_t num = new mpz_t(); gmp_lib.mpz_init(num); // Set integer to numerator of rational, and increment integer by 2. gmp_lib.mpq_get_num(num, op); gmp_lib.mpz_add_ui(num, num, 2U); // Assert that num is 1, and op is -1 / 3. Assert.IsTrue(gmp_lib.mpz_cmp_si(num, 1) == 0); Assert.IsTrue(gmp_lib.mpq_cmp_si(op, -1, 3U) == 0); // Release unmanaged memory allocated for op and num. gmp_lib.mpq_clear(op); gmp_lib.mpz_clear(num);