gmp_lib.mpz_set_str Method

GMP Native Interface for .NET

gmp_libmpz_set_str Method
Set the value of rop from str, a null-terminated C string 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 int mpz_set_str(
	mpz_t rop,
	char_ptr str,
	int base
)
Public Shared Function mpz_set_str ( 
	rop As mpz_t,
	str As char_ptr,
	base As Integer
) As Integer
public:
static int mpz_set_str(
	mpz_t^ rop, 
	char_ptr str, 
	int base
)
static member mpz_set_str : 
        rop : mpz_t * 
        str : char_ptr * 
        base : int -> int 

Parameters

rop
Type: Math.Gmp.Nativempz_t
The destination integer.
str
Type: Math.Gmp.Nativechar_ptr
The source integer.
base
Type: SystemInt32
The base.

Return Value

Type: Int32
This function returns 0 if the entire string is a valid number in base base. Otherwise it returns −1.
Remarks

White space is allowed in the string, and is simply ignored.

The base may vary from 2 to 62, or if base is 0, then the leading characters are used: 0x and 0X for hexadecimal, 0b and 0B for binary, 0 for octal, or decimal otherwise.

For bases up to 36, case is ignored; upper-case and lower-case letters have the same value. For bases 37 to 62, upper-case letter represent the usual 10..35 while lower-case letter represent 36..61.

Examples
// Create and initialize a new integer x.
mpz_t x = new mpz_t();
gmp_lib.mpz_init(x);

// Set the value of x.
char_ptr value = new char_ptr("12 345 678 909 876 543 211 234 567 890 987 654 321");
gmp_lib.mpz_set_str(x, value, 10);

// Assert the value of x.
char_ptr s = gmp_lib.mpz_get_str(char_ptr.Zero, 10, x);
Assert.IsTrue(s.ToString() == value.ToString().Replace(" ", ""));

// Release unmanaged memory allocated for x and string values.
gmp_lib.mpz_clear(x);
gmp_lib.free(value);
gmp_lib.free(s);
' Create and initialize a new integer x.
Dim x As New mpz_t()
gmp_lib.mpz_init(x)

' Set the value of x.
Dim value As New char_ptr("12 345 678 909 876 543 211 234 567 890 987 654 321")
gmp_lib.mpz_set_str(x, value, 10)

' Assert the value of x.
Dim s As char_ptr = gmp_lib.mpz_get_str(char_ptr.Zero, 10, x)
Assert.IsTrue(s.ToString() = value.ToString().Replace(" ", ""))

' Release unmanaged memory allocated for x and string values.
gmp_lib.mpz_clear(x)
gmp_lib.free(value)
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