gmp_lib.mpq_out_str Method

GMP Native Interface for .NET

gmp_libmpq_out_str Method
Output op on stdio stream stream, as 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 size_t mpq_out_str(
	ptr<FILE> stream,
	int base,
	mpq_t op
)
Public Shared Function mpq_out_str ( 
	stream As ptr(Of FILE),
	base As Integer,
	op As mpq_t
) As size_t
public:
static size_t mpq_out_str(
	ptr<FILE>^ stream, 
	int base, 
	mpq_t^ op
)
static member mpq_out_str : 
        stream : ptr<FILE> * 
        base : int * 
        op : mpq_t -> size_t 

Parameters

stream
Type: Math.Gmp.NativeptrFILE
Pointer to file stream.
base
Type: SystemInt32
The base.
op
Type: Math.Gmp.Nativempq_t
The operand rational.

Return Value

Type: size_t
Return the number of bytes written, or if an error occurred, return 0.
Remarks

The base may vary from 2 to 36. Output is in the form "num/den" or if the denominator is 1 then just "num".

Examples
// Create, initialize, and set the value of op to 123/456.
mpq_t op = new mpq_t();
gmp_lib.mpq_init(op);
gmp_lib.mpq_set_ui(op, 123, 456U);

// Get a temporary file.
string pathname = System.IO.Path.GetTempFileName();

// Open temporary file for writing.
ptr<FILE> stream = new ptr<FILE>();
_wfopen_s(out stream.Value.Value, pathname, "w");

// Write op to temporary file, and assert that the number of bytes written is 7.
Assert.IsTrue(gmp_lib.mpq_out_str(stream, 10, op) == 7);

// Close temporary file.
fclose(stream.Value.Value);

// Assert that the content of the temporary file is "123/456".
string result = System.IO.File.ReadAllText(pathname);
Assert.IsTrue(result == "123/456");

// Delete temporary file.
System.IO.File.Delete(pathname);

// Release unmanaged memory allocated for op.
gmp_lib.mpq_clear(op);
' Create, initialize, and set the value of op to 123/456.
Dim op As New mpq_t()
gmp_lib.mpq_init(op)
gmp_lib.mpq_set_ui(op, 123, 456UI)

' Get a temporary file.
Dim pathname As String = System.IO.Path.GetTempFileName()

' Open temporary file for writing.
Dim stream As New ptr(Of FILE)()
_wfopen_s(stream.Value.Value, pathname, "w")

' Write op to temporary file, and assert that the number of bytes written is 7.
Assert.IsTrue(gmp_lib.mpq_out_str(stream, 10, op) = 7)

' Close temporary file.
fclose(stream.Value.Value)

' Assert that the content of the temporary file is "123/456".
Dim result As String = System.IO.File.ReadAllText(pathname)

Assert.IsTrue(result = "123/456")

' Delete temporary file.
System.IO.File.Delete(pathname)

' Release unmanaged memory allocated for op.
gmp_lib.mpq_clear(op)

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