gmp_libmpf_out_str Method |
Namespace: Math.Gmp.Native
public static size_t mpf_out_str( ptr<FILE> stream, int base, size_t n_digits, mpf_t op )
The mantissa is prefixed with an "0." and is in the given base, which may vary from 2 to 62 or from -2 to -36. An exponent is then printed, separated by an "e", or if the base is greater than 10 then by an "@". The exponent is always in decimal. The decimal point follows the current locale, on systems providing localeconv.
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.
Up to n_digits will be printed from the mantissa, except that no more digits than are accurately representable by op will be printed. n_digits can be 0 to select that accurate maximum.
// Create, initialize, and set the value of op to 123456. mpf_t op = new mpf_t(); gmp_lib.mpf_init_set_ui(op, 123456U); // 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 10. Assert.IsTrue(gmp_lib.mpf_out_str(stream, 10, 0, op) == 10); // Close temporary file. fclose(stream.Value.Value); // Assert that the content of the temporary file is "123456". string result = System.IO.File.ReadAllText(pathname); Assert.IsTrue(result == "0.123456e6"); // Delete temporary file. System.IO.File.Delete(pathname); // Release unmanaged memory allocated for op. gmp_lib.mpf_clear(op);