gmp_lib.mpf_get_str Method (char_ptr, mp_exp_t, Int32, size_t, mpf_t)

GMP Native Interface for .NET

gmp_libmpf_get_str Method (char_ptr, mp_exp_t, Int32, size_t, mpf_t)
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 mpf_get_str(
	char_ptr str,
	ref mp_exp_t expptr,
	int base,
	size_t n_digits,
	mpf_t op
)
Public Shared Function mpf_get_str ( 
	str As char_ptr,
	ByRef expptr As mp_exp_t,
	base As Integer,
	n_digits As size_t,
	op As mpf_t
) As char_ptr
public:
static char_ptr mpf_get_str(
	char_ptr str, 
	mp_exp_t% expptr, 
	int base, 
	size_t n_digits, 
	mpf_t^ op
)
static member mpf_get_str : 
        str : char_ptr * 
        expptr : mp_exp_t byref * 
        base : int * 
        n_digits : size_t * 
        op : mpf_t -> char_ptr 

Parameters

str
Type: Math.Gmp.Nativechar_ptr
The output string.
expptr
Type: Math.Gmp.Nativemp_exp_t
The exponent.
base
Type: SystemInt32
The base.
n_digits
Type: Math.Gmp.Nativesize_t
Maximum number of output digits.
op
Type: Math.Gmp.Nativempf_t
The operand floating-point number.

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. Up to n_digits digits will be generated. Trailing zeros are not returned. No more digits than can be accurately represented by op are ever generated. If n_digits is 0 then that accurate maximum number of digits are generated.

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 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 n_digits + 2 bytes, that being enough for the mantissa, a possible minus sign, and a null-terminator. When n_digits is 0 to get all significant digits, an application won’t be able to know the space required, and str should be NULL in that case.

The generated string is a fraction, with an implicit radix point immediately to the left of the first digit. The applicable exponent is written through the expptr pointer. For example, the number 3.1416 would be returned as string "31416" and exponent 1.

When op is zero, an empty string is produced and the exponent returned is 0.

Examples
// Set default precision to 64 bits.
gmp_lib.mpf_set_default_prec(64U);

// Create, initialize, and set a new floating-point number to -8.0
mpf_t x = new mpf_t();
gmp_lib.mpf_init_set_d(x, -8.0);

// Assert that the value of x is -8.
mp_exp_t exp = 0;
char_ptr value = gmp_lib.mpf_get_str(char_ptr.Zero, ref exp, 10, 0, x);
Assert.IsTrue(value.ToString() == "-8");
Assert.IsTrue(exp == 1);

// Release unmanaged memory allocated for x.
gmp_lib.mpf_clear(x);
gmp_lib.free(value);
' Set default precision to 64 bits.
gmp_lib.mpf_set_default_prec(64UI)

' Create, initialize, and set a new floating-point number to -8.0
Dim x As New mpf_t()
gmp_lib.mpf_init_set_d(x, -8.0)

' Assert that the value of x is -8.
Dim exp As mp_exp_t = 0
Dim value As char_ptr = gmp_lib.mpf_get_str(char_ptr.Zero, exp, 10, 0, x)
Assert.IsTrue(value.ToString() = "-8")
Assert.IsTrue(exp = 1)

' Release unmanaged memory allocated for x.
gmp_lib.mpf_clear(x)
gmp_lib.free(value)

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