gmp_libmpf_set_prec_raw Method |
Namespace: Math.Gmp.Native
Assembly: Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)

public static void mpf_set_prec_raw( mpf_t rop, mp_bitcnt_t prec )
Public Shared Sub mpf_set_prec_raw ( rop As mpf_t, prec As mp_bitcnt_t )
public: static void mpf_set_prec_raw( mpf_t^ rop, mp_bitcnt_t prec )
static member mpf_set_prec_raw : rop : mpf_t * prec : mp_bitcnt_t -> unit
Parameters
- rop
- Type: Math.Gmp.Nativempf_t
The result float. - prec
- Type: Math.Gmp.Nativemp_bitcnt_t
The minimum precision in bits.

prec must be no more than the allocated precision for rop, that being the precision when rop was initialized, or in the most recent mpf_set_prec.
The value in rop is unchanged, and in particular if it had a higher precision than prec it will retain that higher precision. New values written to rop will use the new prec.
Before calling mpf_clear or the full mpf_set_prec, another mpf_set_prec_raw call must be made to restore rop to its original allocated precision. Failing to do so will have unpredictable results.
mpf_get_prec can be used before mpf_set_prec_raw to get the original allocated precision. After mpf_set_prec_raw it reflects the prec value set.
mpf_set_prec_raw is an efficient way to use an mpf_t variable at different precisions during a calculation, perhaps to gradually increase precision in an iteration, or just to use various different precisions for different purposes during a calculation.

// Set default precision to 128 bits. gmp_lib.mpf_set_default_prec(128U); // Create, initialize, and set a new rational y to 200 / 3. mpq_t y = new mpq_t(); gmp_lib.mpq_init(y); gmp_lib.mpq_set_ui(y, 200, 3U); // Create, initialize, and set a new floating-point number x to y. mpf_t x = new mpf_t(); gmp_lib.mpf_init(x); gmp_lib.mpf_set_q(x, y); Assert.IsTrue(x.ToString() == "0.6666666666666666666666666666666666666667e2"); // Change precision of x, and set its value to 10000 / 3. gmp_lib.mpf_set_prec_raw(x, 8U); gmp_lib.mpq_set_ui(y, 10000, 3U); gmp_lib.mpf_set_q(x, y); Assert.IsTrue(x.ToString() == "0.333333333333333333333e4"); // Restore precision of x. gmp_lib.mpf_set_prec_raw(x, 128U); // Release unmanaged memory allocated for x and y. gmp_lib.mpf_clear(x); gmp_lib.mpq_clear(y);
' Set default precision to 128 bits. gmp_lib.mpf_set_default_prec(128UI) ' Create, initialize, and set a new rational y to 200 / 3. Dim y As New mpq_t() gmp_lib.mpq_init(y) gmp_lib.mpq_set_ui(y, 200, 3UI) ' Create, initialize, and set a new floating-point number x to y. Dim x As New mpf_t() gmp_lib.mpf_init(x) gmp_lib.mpf_set_q(x, y) Assert.IsTrue(x.ToString() = "0.6666666666666666666666666666666666666667e2") ' Change precision of x, and set its value to 10000 / 3. gmp_lib.mpf_set_prec_raw(x, 8UI) gmp_lib.mpq_set_ui(y, 10000, 3UI) gmp_lib.mpf_set_q(x, y) Assert.IsTrue(x.ToString() = "0.333333333333333333333e4") ' Restore precision of x. gmp_lib.mpf_set_prec_raw(x, 128UI) ' Release unmanaged memory allocated for x and y. gmp_lib.mpf_clear(x) gmp_lib.mpq_clear(y)
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.
