Reputation: 189
I searched for some hours on internet and through the docs, but I didn't see mention to create an array/list of MPFR (GMP) objects. I am using C, not C++. I you would please help me, I'd only need to get and set values from and to that array, and perhaps a "malloc" once..
Upvotes: 0
Views: 603
Reputation: 3689
In this GNU MPFR 4.0.2, i found:
The C data type for such objects is mpfr_t, internally defined as a one-element array of a structure (so that when passed as an argument to a function, it is the pointer that is actually passed), and mpfr_ptr is the C data type representing a pointer to this structure.
And at 5.1 initialization function:
An mpfr_t object must be initialized before storing the first value in it. The functions mpfr_init and mpfr_init2 are used for that purpose.
Function: void mpfr_init2 (mpfr_t x, mpfr_prec_t prec)
Initialize x, set its precision to be exactly prec bits and its value to NaN. (Warning: the corresponding MPF function initializes to zero instead.)
Normally, a variable should be initialized once only or at least be cleared, using mpfr_clear, between initializations. To change the precision of a variable which has already been initialized, use mpfr_set_prec. The precision prec must be an integer between MPFR_PREC_MIN and MPFR_PREC_MAX (otherwise the behavior is undefined).
Function: void mpfr_inits2 (mpfr_prec_t prec, mpfr_t x, ...)
Initialize all the mpfr_t variables of the given variable argument va_list, set their precision to be exactly prec bits and their value to NaN. See mpfr_init2 for more details. The va_list is assumed to be composed only of type mpfr_t (or equivalently mpfr_ptr). It begins from x, and ends when it encounters a null pointer (whose type must also be mpfr_ptr).
One example:
{
mpfr_t x, y;
mpfr_init (x); /* use default precision */
mpfr_init2 (y, 256); /* precision exactly 256 bits */
…
/* When the program is about to exit, do ... */
mpfr_clear (x);
mpfr_clear (y);
mpfr_free_cache (); /* free the cache for constants like pi */
}
Hope it can help you.
Upvotes: 2