gmp_libmpf_init_set_str Method |
Namespace: Math.Gmp.Native
See mpf_set_str(mpf_t, char_ptr, Int32) for details on the assignment operation.
Note that rop is initialized even if an error occurs. (I.e., you have to call mpf_clear(mpf_t) for it.)
The precision of rop will be taken from the active default precision, as set by mpf_set_default_prec(mp_bitcnt_t).
// Set default precision to 64 bits. gmp_lib.mpf_set_default_prec(64U); // Create, initialize, and set a new floating-point number x to 0.0234. char_ptr value = new char_ptr("234e-4"); mpf_t x = new mpf_t(); gmp_lib.mpf_init_set_str(x, value, 10); // Assert that x is 40. Assert.IsTrue(x.ToString() == "0.234e-1"); // Release unmanaged memory allocated for x and y. gmp_lib.mpf_clear(x); gmp_lib.free(value);