Click or drag to resize
gmp_libmpf_get_str Method (char_ptr, ptrmp_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,
	ptr<mp_exp_t> expptr,
	int base,
	size_t n_digits,
	mpf_t op
)

Parameters

str
Type: Math.Gmp.Nativechar_ptr
The output string.
expptr
Type: Math.Gmp.Nativeptrmp_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.
ptr<mp_exp_t> exp = new ptr<mp_exp_t>(0);
char_ptr value = gmp_lib.mpf_get_str(char_ptr.Zero, exp, 10, 0, x);
Assert.IsTrue(value.ToString() == "-8");
Assert.IsTrue(exp.Value == 1);

// Release unmanaged memory allocated for x.
gmp_lib.mpf_clear(x);
gmp_lib.free(value);
See Also