如何创建 mpfr 数组?
How to create a mpfr array?
我在互联网上和文档中搜索了几个小时,但没有看到提及创建 MPFR (GMP) 对象的 array/list。
我使用的是 C,而不是 C++。
我会请你帮助我,我只需要从那个数组获取和设置值,也许 "malloc" 一次..
在这个GNU MPFR 4.0.2中,我发现:
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.
而在5.1初始化函数:
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).
一个例子:
{
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 */
}
希望对您有所帮助。
我在互联网上和文档中搜索了几个小时,但没有看到提及创建 MPFR (GMP) 对象的 array/list。 我使用的是 C,而不是 C++。 我会请你帮助我,我只需要从那个数组获取和设置值,也许 "malloc" 一次..
在这个GNU MPFR 4.0.2中,我发现:
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.
而在5.1初始化函数:
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).
一个例子:
{
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 */
}
希望对您有所帮助。