gmp_libmpq_get_str Method |
Namespace: Math.Gmp.Native
Assembly: Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)

public static char_ptr mpq_get_str( char_ptr str, int base, mpq_t op )
Public Shared Function mpq_get_str ( str As char_ptr, base As Integer, op As mpq_t ) As char_ptr
public: static char_ptr mpq_get_str( char_ptr str, int base, mpq_t^ op )
static member mpq_get_str : str : char_ptr * base : int * op : mpq_t -> char_ptr
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_ptrA pointer to the result string is returned, being either the allocated block, or the given str.

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);
' Create, initialize, and set the value of x to -210 / 13. Dim x As New mpq_t() gmp_lib.mpq_init(x) gmp_lib.mpq_set_si(x, -210, 13UI) ' Retrieve the string value of x, and assert that it is "-210/13". Dim s As char_ptr = 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)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
