static inline Obj NEW_MPD( mp_prec_t prec ) { Obj f = NEW_DATOBJ(sizeof(__mpd_struct)+2*mpfr_custom_get_size(prec), TYPE_MPD); mpd_ptr p = MPD_OBJ(f); mpfr_custom_init_set(p->re, MPFR_NAN_KIND, 0, prec, REMANTISSA_MPD(p)); mpfr_custom_init_set(p->im, MPFR_NAN_KIND, 0, prec, IMMANTISSA_MPD(p)); return f; }
/* Alloc a new mpfr_t on the main stack */ static mpfr_ptr new_mpfr (mpfr_prec_t p) { mpfr_ptr x = (mpfr_ptr) new_st (sizeof (mpfr_t)); void *mantissa = new_st (mpfr_custom_get_size (p)); mpfr_custom_init (mantissa, p); mpfr_custom_init_set (x, 0, 0, p, mantissa); return x; }
/* a[0] is the kind, a[1] is the exponent, &a[2] is the mantissa */ static long * dummy_new (void) { long *r; r = (long *) new_st (ALIGNED (2 * sizeof (long)) + ALIGNED (mpfr_custom_get_size (p))); (mpfr_custom_init) (&r[2], p); r[0] = (int) MPFR_NAN_KIND; r[1] = 0; return r; }
/* Garbage the stack by keeping only x */ static mpfr_ptr return_mpfr (mpfr_ptr x, char *old_stack) { void *mantissa = mpfr_custom_get_significand (x); size_t size_mantissa = mpfr_custom_get_size (mpfr_get_prec (x)); mpfr_ptr newx; memmove (old_stack, x, sizeof (mpfr_t)); memmove (old_stack + ALIGNED (sizeof (mpfr_t)), mantissa, size_mantissa); newx = (mpfr_ptr) old_stack; mpfr_custom_move (newx, old_stack + ALIGNED (sizeof (mpfr_t))); stack = old_stack + ALIGNED (sizeof (mpfr_t)) + ALIGNED (size_mantissa); return newx; }