gmp_libmpf_inp_str Method |
Namespace: Math.Gmp.Native
The string is of the form "M@N" or, if the base is 10 or less, alternatively "MeN". "M" is the mantissa and "N’" is the exponent. The mantissa is always in the specified base. The exponent is either in the specified base or, if base is negative, in decimal. The decimal point expected is taken from the current locale, on systems providing localeconv.
The argument base may be in the ranges 2 to 36, or -36 to -2. Negative values are used to specify that the exponent is in decimal.
Unlike the corresponding mpz function, the base will not be determined from the leading characters of the string if base is 0. This is so that numbers like "0.23" are not interpreted as octal.
// Create and initialize op. mpf_t op = new mpf_t(); gmp_lib.mpf_init(op); // Write op to a temporary file. string pathname = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllText(pathname, "0.123456e6"); // Read op from the temporary file, and assert that the number of bytes read is 6. ptr<FILE> stream = new ptr<FILE>(); _wfopen_s(out stream.Value.Value, pathname, "r"); Assert.IsTrue(gmp_lib.mpf_inp_str(op, stream, 10) == 10); fclose(stream.Value.Value); // Assert that op is 123456. Assert.IsTrue(gmp_lib.mpf_get_ui(op) == 123456U); // Delete temporary file. System.IO.File.Delete(pathname); // Release unmanaged memory allocated for op. gmp_lib.mpf_clear(op);