gmp_lib.mpz_out_raw Method

GMP Native Interface for .NET

gmp_libmpz_out_raw Method
Output op on stdio stream stream, in raw binary format.

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 mpz_out_raw(
	ptr<FILE> stream,
	mpz_t op
)
Public Shared Function mpz_out_raw ( 
	stream As ptr(Of FILE),
	op As mpz_t
) As size_t
public:
static size_t mpz_out_raw(
	ptr<FILE>^ stream, 
	mpz_t^ op
)
static member mpz_out_raw : 
        stream : ptr<FILE> * 
        op : mpz_t -> size_t 

Parameters

stream
Type: Math.Gmp.NativeptrFILE
Pointer to file streama.
op
Type: Math.Gmp.Nativempz_t
The operand integer.

Return Value

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

The integer is written in a portable format, with 4 bytes of size information, and that many bytes of limbs. Both the size and the limbs are written in decreasing significance order (i.e., in big-endian).

The output can be read with mpz_inp_raw.

The output of this can not be read by mpz_inp_raw from GMP 1, because of changes necessary for compatibility between 32-bit and 64-bit machines.

Examples
// Create, initialize, and set the value of op to 123456 (0x1E240).
mpz_t op = new mpz_t();
gmp_lib.mpz_init_set_ui(op, 0x1E240);

// 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.mpz_out_raw(stream, op) == 7);

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

// Assert that the content of the temporary file.
byte[] r = System.IO.File.ReadAllBytes(pathname);
Assert.IsTrue(r[0] == 0 && r[1] == 0 && r[2] == 0 && r[3] == 3 && r[4] == 0x01 && r[5] == 0xE2 && r[6] == 0x40);

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

// Release unmanaged memory allocated for op.
gmp_lib.mpz_clear(op);
' Create, initialize, and set the value of op to 123456 (0x1E240).
Dim op As New mpz_t()
gmp_lib.mpz_init_set_ui(op, &H1e240)

' 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.mpz_out_raw(stream, op) = 7)

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

' Assert that the content of the temporary file.
Dim r As Byte() = System.IO.File.ReadAllBytes(pathname)
Assert.IsTrue(r(0) = 0 AndAlso r(1) = 0 AndAlso r(2) = 0 AndAlso r(3) = 3 AndAlso r(4) = &H1 AndAlso r(5) = &He2 AndAlso r(6) = &H40)

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

' Release unmanaged memory allocated for op.
gmp_lib.mpz_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