arb/fmpr/abs_bound_lt_2exp_si.c

47 lines
1 KiB
C
Raw Normal View History

/*
Copyright (C) 2013 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#include "fmpr.h"
2015-11-10 13:41:43 +00:00
slong
fmpr_abs_bound_lt_2exp_si(const fmpr_t x)
{
if (fmpr_is_special(x))
{
if (fmpr_is_zero(x))
return -FMPR_PREC_EXACT;
else
return FMPR_PREC_EXACT;
}
else
{
2015-11-05 18:03:08 +00:00
slong res;
fmpz_t t;
fmpz_init(t);
fmpr_abs_bound_lt_2exp_fmpz(t, x);
if (fmpz_fits_si(t))
res = fmpz_get_si(t);
else
res = fmpz_sgn(t) < 0 ? -FMPR_PREC_EXACT : FMPR_PREC_EXACT;
fmpz_clear(t);
if (res < -FMPR_PREC_EXACT)
res = -FMPR_PREC_EXACT;
if (res > FMPR_PREC_EXACT)
res = FMPR_PREC_EXACT;
return res;
}
}