gmp_lib.gmp_vsnprintf Method

GMP Native Interface for .NET

gmp_libgmp_vsnprintf Method
Form a null-terminated string in buf.

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 gmp_vsnprintf(
	char_ptr buf,
	size_t size,
	string fmt,
	params Object[] ap
)
Public Shared Function gmp_vsnprintf ( 
	buf As char_ptr,
	size As size_t,
	fmt As String,
	ParamArray ap As Object()
) As Integer
public:
static int gmp_vsnprintf(
	char_ptr buf, 
	size_t size, 
	String^ fmt, 
	... array<Object^>^ ap
)
static member gmp_vsnprintf : 
        buf : char_ptr * 
        size : size_t * 
        fmt : string * 
        ap : Object[] -> int 

Parameters

buf
Type: Math.Gmp.Nativechar_ptr
The string to print to.
size
Type: Math.Gmp.Nativesize_t
The maximum number of bytes to write.
fmt
Type: SystemString
Format string. See Formatted Output Strings.
ap
Type: SystemObject
Arguments.

Return Value

Type: Int32
The return value is the total number of characters which ought to have been produced, excluding the terminating null. If retval ≥ size then the actual output has been truncated to the first size - 1 characters, and a null appended.
Remarks

No more than size bytes will be written. To get the full output, size must be enough for the string and null-terminator.

No overlap is permitted between the regiom {buf,size} and the fmt string.

Notice the return value is in ISO C99 snprintf style. This is so even if the C library vsnprintf is the older GLIBC 2.0.x style.

Examples
// Allocate unmanaged string with 50 characters.
char_ptr str = new char_ptr(".................................................");

mpz_t z = "123456";
mpq_t q = "123/456";
mpf_t f = "12345e6";
mp_limb_t m = 123456;

// Print to string.
Assert.IsTrue(gmp_lib.gmp_vsnprintf(str, 50, "%Zd - %QX - %Fa - %Mo", z, q, f, m) == 42);
Assert.IsTrue(str.ToString() == "123456 - 7B/1C8 - 0x2.dfd1c04p+32 - 361100");

// Release unmanaged memory.
gmp_lib.free(str);
gmp_lib.mpz_clear(z);
gmp_lib.mpq_clear(q);
gmp_lib.mpf_clear(f);
' Allocate unmanaged string with 50 characters.
Dim str As New char_ptr(".................................................")

Dim z As mpz_t = "123456"
Dim q As mpq_t = "123/456"
Dim f As mpf_t = "12345e6"
Dim m As mp_limb_t = 123456

' Print to string.
Assert.IsTrue(gmp_lib.gmp_vsnprintf(str, 50, "%Zd - %QX - %Fa - %Mo", z, q, f, m) = 42)
Assert.IsTrue(str.ToString() = "123456 - 7B/1C8 - 0x2.dfd1c04p+32 - 361100")

' Release unmanaged memory.
gmp_lib.free(str)
gmp_lib.mpz_clear(z)
gmp_lib.mpq_clear(q)
gmp_lib.mpf_clear(f)

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