gmp_libmpq_get_str Method |
Namespace: Math.Gmp.Native
The base may vary from 2 to 36. The string will be of the form "num/den", or if the denominator is 1 then just "num".
If str is NULL, the result string is allocated using the current allocation function (see GNU MP - Custom Allocation). The block will be strlen(str) + 1 bytes, that being exactly enough for the string and null-terminator.
If str is not NULL, it should point to a block of storage large enough for the result, that being
mpz_sizeinbase(mpq_numref(op), base) + mpz_sizeinbase(mpq_denref(op), base) + 3
The three extra bytes are for a possible minus sign, possible slash, and the null-terminator.
// Create, initialize, and set the value of x to -210 / 13. mpq_t x = new mpq_t(); gmp_lib.mpq_init(x); gmp_lib.mpq_set_si(x, -210, 13U); // Retrieve the string value of x, and assert that it is "-210/13". char_ptr s = gmp_lib.mpq_get_str(char_ptr.Zero, 10, x); Assert.IsTrue(s.ToString() == "-210/13"); // Release unmanaged memory allocated for x and the string value. gmp_lib.mpq_clear(x); gmp_lib.free(s);