/* Set f to z, choosing the smallest precision for f so that z = f*(2^BPML)*zs*2^(RetVal)  */
static int set_z(mpfr_ptr f, mpz_srcptr z, mp_size_t *zs)
/* Set f to z, choosing the smallest precision for f so that z = f*(2^BPML)*zs*2^(RetVal)  */
static int set_z(mpfr_ptr f, mpz_srcptr z, mp_size_t *zs)
{
  mp_limb_t *p;
  mp_size_t s;
  int c;
  mpfr_prec_t pf;
  MPFR_ASSERTD (mpz_sgn (z) != 0);
  for (p = PTR (z), s = *zs = ABS (SIZ (z)) ; *p == 0; p++, s--)
    MPFR_ASSERTD (s >= 0);
  count_leading_zeros (c, p[s-1]);
  pf = s * GMP_NUMB_BITS - c;
  if (pf < MPFR_PREC_MIN)
    pf = MPFR_PREC_MIN;
  mpfr_init2 (f, pf);
  if (MPFR_LIKELY (c))
    mpn_lshift (MPFR_MANT (f), p, s, c);
  else
    MPN_COPY (MPFR_MANT (f), p, s);
  MPFR_SET_SIGN (f, mpz_sgn (z));
  MPFR_SET_EXP (f, 0);
  return -c;
}