catch overflow when converting to mpfr

This commit is contained in:
Fredrik Johansson 2012-09-07 12:46:58 +02:00
parent 0847d21f66
commit 849e713207

11
fmpr.h
View file

@ -227,12 +227,23 @@ fmpr_get_mpfr(mpfr_t x, const fmpr_t y, mpfr_rnd_t rnd)
else mpfr_set_nan(x);
r = 0;
}
else if (COEFF_IS_MPZ(*fmpr_expref(y)))
{
printf("exception: exponent too large to convert to mpfr");
abort();
}
else
{
if (!COEFF_IS_MPZ(*fmpr_manref(y)))
r = mpfr_set_si_2exp(x, *fmpr_manref(y), *fmpr_expref(y), rnd);
else
r = mpfr_set_z_2exp(x, COEFF_TO_PTR(*fmpr_manref(y)), *fmpr_expref(y), rnd);
if (!mpfr_regular_p(x))
{
printf("exception: exponent too large to convert to mpfr");
abort();
}
}
return r;