Click or drag to resize
gmp_libmpq_inp_str Method
Read a string of digits from stream and convert them to a rational in rop.

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_inp_str(
	mpq_t rop,
	ptr<FILE> stream,
	int base
)

Parameters

rop
Type: Math.Gmp.Nativempq_t
The result rational.
stream
Type: Math.Gmp.NativeptrFILE
Pointer to file stream.
base
Type: SystemInt32
The base.

Return Value

Type: size_t
Return the number of characters read (including white space), or 0 if a rational could not be read.
Remarks

Any initial white-space characters are read and discarded.

The input can be a fraction like "17/63" or just an integer like "123". Reading stops at the first character not in this form, and white space is not permitted within the string. If the input might not be in canonical form, then mpq_canonicalize must be called (see GNU MP - Rational Number Functions).

The base can be between 2 and 36, or can be 0 in which case the leading characters of the string determine the base, "0x" or "0X" for hexadecimal, "0" for octal, or decimal otherwise. The leading characters are examined separately for the numerator and denominator of a fraction, so for instance "0x10/11" is 16/11, whereas "0x10/0x11" is 16/17.

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

// Write rational to a temporary file.
string pathname = System.IO.Path.GetTempFileName();
System.IO.File.WriteAllText(pathname, "123/456");

// Read op from the temporary file, and assert that the number of bytes read is 7.
ptr<FILE> stream = new ptr<FILE>();
_wfopen_s(out stream.Value.Value, pathname, "r");
Assert.IsTrue(gmp_lib.mpq_inp_str(op, stream, 10) == 7);
fclose(stream.Value.Value);

// Assert that op is 123/456.
Assert.IsTrue(gmp_lib.mpq_cmp_ui(op, 123, 456U) == 0);

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

// Release unmanaged memory allocated for op.
gmp_lib.mpq_clear(op);
See Also