Next: Internals, Previous: Compatibility with MPF, Up: MPFR Interface
Some applications use a stack to handle the memory and their objects. However, the MPFR memory design is not well suited for such a thing. So that such applications are able to use MPFR, an auxiliary memory interface has been created: the Custom Interface.
The following interface allows them to use MPFR in two ways:
mpfr_t
on the stack.
mpfr_t
each time it is needed.
Each function in this interface is also implemented as a macro for
efficiency reasons: for example mpfr_custom_init (s, p)
uses the macro, while (mpfr_custom_init) (s, p)
uses the function.
Note 1: MPFR functions may still initialize temporary FP numbers using standard mpfr_init. See Custom Allocation (GNU MP).
Note 2: MPFR functions may use the cached functions (mpfr_const_pi for
example), even if they are not explicitly called. You have to call
mpfr_free_cache
each time you garbage the memory iff mpfr_init, through
GMP Custom Allocation, allocates its memory on the application stack.
Note 3: This interface is preliminary.
Return the needed size in bytes to store the significand of a FP number of precision prec.
Initialize a significand of precision prec. significand must be an area of
mpfr_custom_get_size (prec)
bytes at least and be suitably aligned for an array ofmp_limb_t
.
Perform a dummy initialization of a
mpfr_t
and set it to:In all cases, it uses significand directly for further computing involving x. It will not allocate anything. A FP number initialized with this function cannot be resized using
- if
ABS(kind) == MPFR_NAN_KIND
, x is set to NaN;- if
ABS(kind) == MPFR_INF_KIND
, x is set to the infinity of signsign(kind)
;- if
ABS(kind) == MPFR_ZERO_KIND
, x is set to the zero of signsign(kind)
;- if
ABS(kind) == MPFR_REGULAR_KIND
, x is set to a regular number:x = sign(kind)*significand*2^exp
mpfr_set_prec
, or cleared usingmpfr_clear
! significand must have been initialized withmpfr_custom_init
using the same precision prec.
Return the current kind of a
mpfr_t
as used bympfr_custom_init_set
. The behavior of this function for anympfr_t
not initialized withmpfr_custom_init_set
is undefined.
Return a pointer to the significand used by a
mpfr_t
initialized withmpfr_custom_init_set
. The behavior of this function for anympfr_t
not initialized withmpfr_custom_init_set
is undefined.
Return the exponent of x, assuming that x is a non-zero ordinary number. The return value for NaN, Infinity or Zero is unspecified but does not produce any trap. The behavior of this function for any
mpfr_t
not initialized withmpfr_custom_init_set
is undefined.
Inform MPFR that the significand has moved due to a garbage collect and update its new position to
new_position
. However the application has to move the significand and thempfr_t
itself. The behavior of this function for anympfr_t
not initialized withmpfr_custom_init_set
is undefined.
See the test suite for examples.