gmp_lib.mpz_get_str Method

GMP Native Interface for .NET

gmp_libmpz_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 mpz_get_str(
	char_ptr str,
	int base,
	mpz_t op
)
Public Shared Function mpz_get_str ( 
	str As char_ptr,
	base As Integer,
	op As mpz_t
) As char_ptr
public:
static char_ptr mpz_get_str(
	char_ptr str, 
	int base, 
	mpz_t^ op
)
static member mpz_get_str : 
        str : char_ptr * 
        base : int * 
        op : mpz_t -> char_ptr 

Parameters

str
Type: Math.Gmp.Nativechar_ptr
The converted integer.
base
Type: SystemInt32
The base.
op
Type: Math.Gmp.Nativempz_t
The integer.

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 argument may vary from 2 to 62 or from −2 to −36.

For base in the range 2..36, digits and lower-case letters are used; for −2..−36, digits and upper-case letters are used; for 37..62, digits, upper-case letters, and lower-case letters (in that significance order) are used.

If str is char_ptr.Zero, the result string is allocated using the current allocation function. The block will be strlen(str)+1 bytes, that being exactly enough for the string and null-terminator.

If str is not char_ptr.Zero, it should point to a block of storage large enough for the result, that being mpz_sizeinbase(op, base) + 2. The two extra bytes are for a possible minus sign, and the null-terminator.

Examples
// Create, initialize, and set the value of x to -210.
mpz_t x = new mpz_t();
gmp_lib.mpz_init_set_si(x, -210);

// Retrieve the string value of x, and assert that it is "-210".
char_ptr s = gmp_lib.mpz_get_str(char_ptr.Zero, 10, x);
Assert.IsTrue(s.ToString() == "-210");

// Release unmanaged memory allocated for x and the string value.
gmp_lib.mpz_clear(x);
gmp_lib.free(s);
' Create, initialize, and set the value of x to -210.
Dim x As New mpz_t()
gmp_lib.mpz_init_set_si(x, -210)

' Retrieve the string value of x, and assert that it is "-210".
Dim s As char_ptr = gmp_lib.mpz_get_str(char_ptr.Zero, 10, x)
Assert.IsTrue(s.ToString() = "-210")

' Release unmanaged memory allocated for x and the string value.
gmp_lib.mpz_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.

See Also