Click or drag to resize
gmp_libmpq_get_str Method
Convert op to a string of digits in base base.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static char_ptr mpq_get_str(
	char_ptr str,
	int base,
	mpq_t op
)

Parameters

str
Type: Math.Gmp.Nativechar_ptr
The result string.
base
Type: SystemInt32
The base.
op
Type: Math.Gmp.Nativempq_t
The operand rational.

Return Value

Type: char_ptr
A pointer to the result string is returned, being either the allocated block, or the given str.
Remarks

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

C++
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.

Examples
// 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);
See Also